麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發(fā) > PHP > 正文

如何批量清理系統(tǒng)臨時文件(語言:C#、 C/C++、 php 、python 、java )

2024-05-04 23:42:40
字體:
供稿:網(wǎng)友
這篇文章主要介紹了如何批量清理系統(tǒng)臨時文件(C# C/C++ php python java )的相關資料,需要的朋友可以參考下
 

語言之爭由來已久,下面做一些IO實驗(遍歷9G多的文件,批量刪除),盡量用事實來比較誰優(yōu)誰劣。操作系統(tǒng):win7 64 位,文件包大小:9.68G。

一、語言:C#

開發(fā)環(huán)境:vs 2013

代碼總行數(shù):43行

耗時:7秒

代碼:

using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;namespace BatchDelete{class Program{static void Main(string[] args){// 輸入目錄 e:/tmpstring path;Console.WriteLine("輸入要清理的目錄:");path = Console.ReadLine();// 開始計時Console.WriteLine("開始計時:"+DateTime.Now.ToString("HH:mm:ss"));// 先遍歷匹配查找再循環(huán)刪除if (Directory.Exists(path)){Console.Write("正在刪除");foreach (string fileName in Directory.GetFileSystemEntries(path)){if (File.Exists(fileName) && fileName.Contains("cachegrind.out")){File.Delete(fileName);}}Console.WriteLine("");}else{Console.WriteLine("該目錄不存在!");}// 計時結束Console.WriteLine("結束計時:" + DateTime.Now.ToString("HH:mm:ss"));Console.ReadKey();}}}

運行效果圖:

如何批量清理系統(tǒng)臨時文件(語言:C#、 C/C++、 php 、python 、java )

二、語言:C/C++

開發(fā)環(huán)境:vs 2013

代碼總行數(shù):50行

耗時:36秒

代碼:

#include <iostream>#include <string>#include <Windows.h>#include <boost/filesystem/operations.hpp>#include <boost/filesystem/path.hpp>#include <boost/filesystem/convenience.hpp>#include <boost/algorithm/string.hpp>using namespace std;int main(int argc, char * argv[]){// 輸入目錄 e:/tmpstring strPath;cout << "輸入要清理的目錄:" << endl;getline(cin, strPath);// 開始計時 SYSTEMTIME sys_time; //聲明變量GetLocalTime(&sys_time); //將變量值設置為本地時間printf("開始計時:%02d:%02d:%02d/n", sys_time.wHour,sys_time.wMinute,sys_time.wSecond);// 先遍歷匹配查找再循環(huán)刪除namespace fs = boost::filesystem;fs::path full_path(fs::initial_path());full_path = fs::system_complete(fs::path(strPath, fs::native));if (fs::exists(full_path)){cout << "正在刪除" ;fs::directory_iterator item_begin(full_path);fs::directory_iterator item_end;for (; item_begin != item_end; item_begin++){if (!fs::is_directory(*item_begin)){if (fs::exists(item_begin->path()) && boost::contains(item_begin->path().string(), "cachegrind.out")){fs::remove(item_begin->path());}}}cout << "" << endl;}else{cout << "該目錄不存在!" << endl;}// 計時結束GetLocalTime(&sys_time);printf("計時結束:%02d:%02d:%02d/n", sys_time.wHour, sys_time.wMinute, sys_time.wSecond);system("pause");return 0;}

運行效果圖:

如何批量清理系統(tǒng)臨時文件(語言:C#、 C/C++、 php 、python 、java )

三、語言:PHP

開發(fā)環(huán)境:Phpstorm

代碼總行數(shù):32行

耗時:13秒

代碼:

<?php/*** Created by PhpStorm.* User: Administrator* Date: 16-1-29* Time: 上午9:31*/date_default_timezone_set('prc');//輸入目錄 e:/tmp$path = 'e:/tmp';//開始計時echo date("H:i:s",time()) . '<br/>';//先遍歷匹配查找再循環(huán)刪除if(is_dir($path)){echo "正在刪除";$mydir = dir($path);while($file = $mydir->read()){if(file_exists("$path/$file") && strpos($file, 'cachegrind.out') === 0){unlink("$path/$file");}}echo '<br/>';}else{echo "該目錄不存在!" . '<br/>';}//計時結束echo date("H:i:s",time()) . '<br/>'; 

運行效果圖:

如何批量清理系統(tǒng)臨時文件(語言:C#、 C/C++、 php 、python 、java )

四、語言:Java

開發(fā)環(huán)境:eclipse

代碼總行數(shù):43行

耗時:10秒

代碼:

package com.yejing;import java.io.File;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner s = new Scanner(System.in);// 輸入目錄 e:/tmpString path = null;System.out.println("輸入要清理的目錄:");path = s.next();// 開始計時Date nowTime=new Date(); SimpleDateFormat time=new SimpleDateFormat("HH:mm:ss"); System.out.println("開始計時:"+ time.format(nowTime)); // 先遍歷匹配查找再循環(huán)刪除File dir = new File(path);if(dir.exists()){System.out.print("正在刪除");File[] fs = dir.listFiles();for(int i=0;i<fs.length;i++){if(!fs[i].isDirectory()){if(fs[i].isFile() && fs[i].exists() && fs[i].getName().contains("cachegrind.out")){fs[i].delete(); }}}System.out.println("");}else{System.out.println("該目錄不存在!");}// 計時結束nowTime=new Date(); System.out.println("開始計時:"+ time.format(nowTime)); }}

運行效果圖:

如何批量清理系統(tǒng)臨時文件(語言:C#、 C/C++、 php 、python 、java )

五、語言:Python 3.3.5

開發(fā)環(huán)境:IDLE

代碼總行數(shù):20行

耗時:10秒

代碼:

# -*- coding: utf-8 -*- import datetimeimport os# 輸入目錄 e:/tmppath = input("輸入要清理的目錄:/n");# 開始計時print("開始計時:",datetime.datetime.now().strftime('%H:%M:%S'));# 先遍歷匹配查找再循環(huán)刪除if(os.path.exists(path)):print("正在刪除");for parent,dirnames,filenames in os.walk(path):for filename in filenames:targetFile = os.path.join(parent,filename)if (os.path.isfile(targetFile) and "cachegrind.out" in targetFile):os.remove(targetFile)

else:

print("該目錄不存在!");# 計時結束print("結束計時:",datetime.datetime.now().strftime('%H:%M:%S')); 

運行效果圖:

如何批量清理系統(tǒng)臨時文件(語言:C#、 C/C++、 php 、python 、java )



注:相關教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 在线观看福利网站 | 毛片免费视频在线观看 | 国产又粗又爽又深的免费视频 | 在线91视频 | 日韩黄色影视 | av电影免费播放 | 色阁五月| 免费观看三级毛片 | 日韩大片在线永久观看视频网站免费 | 96视频在线免费观看 | 色网站综合 | 污污黄| 中文字幕激情 | 欧美日韩在线免费观看 | 性盈盈盈影院 | 蜜桃av鲁一鲁一鲁一鲁 | 精品国产一区二区三区蜜殿 | 精品国产一区二区在线观看 | 奶子吧naiziba.cc免费午夜片在线观看 | 久久精品视频一区 | 视频一区二区在线观看 | 欧美大胆xxxx肉体摄影 | 黄污视频在线看 | 久久99亚洲精品 | 鲁久久 | 91快色| xxxx欧美视频 | 99精彩视频在线观看 | 免费一级欧美大片视频 | 国产不卡av在线 | 久久96国产精品久久秘臀 | 毛片大全在线观看 | 5xx免费看| 国产99久久久国产精品下药 | 91色琪琪电影亚洲精品久久 | 国产精品久久久久久影视 | 欧美激情在线播放 | 免费黄色在线 | 综合网天天射 | 欧美日韩亚洲在线 | 国产成年人视频 |