亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2016年02月01日 16:38:18   作者:文藝青年.茶  
這篇文章主要介紹了如何批量清理系統(tǒng)臨時文件(C# C/C++ php python java )的相關(guān)資料,需要的朋友可以參考下

語言之爭由來已久,下面做一些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:\tmp
string 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("該目錄不存在!");
}
// 計時結(jié)束
Console.WriteLine("結(jié)束計時:" + DateTime.Now.ToString("HH:mm:ss"));
Console.ReadKey();
}
}
}

運行效果圖:


二、語言: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:\tmp
string strPath;
cout << "輸入要清理的目錄:" << endl;
getline(cin, strPath);
// 開始計時 
SYSTEMTIME sys_time; //聲明變量
GetLocalTime(&sys_time); //將變量值設(shè)置為本地時間
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;
}
// 計時結(jié)束
GetLocalTime(&sys_time);
printf("計時結(jié)束:%02d:%02d:%02d\n", sys_time.wHour, sys_time.wMinute, sys_time.wSecond);
system("pause");
return 0;
}

運行效果圖:


三、語言: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/>';
}
//計時結(jié)束
echo date("H:i:s",time()) . '<br/>'; 

運行效果圖:


四、語言: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:\tmp
String 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("該目錄不存在!");
}
// 計時結(jié)束
nowTime=new Date(); 
System.out.println("開始計時:"+ time.format(nowTime)); 
}
}

運行效果圖:

五、語言:Python 3.3.5

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

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

耗時:10秒

代碼:

# -*- coding: utf-8 -*- 
import datetime
import os
# 輸入目錄 e:\tmp
path = 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("該目錄不存在!");
# 計時結(jié)束
print("結(jié)束計時:",datetime.datetime.now().strftime('%H:%M:%S')); 

運行效果圖:

相關(guān)文章

  • php版小黃雞simsimi聊天機器人接口分享

    php版小黃雞simsimi聊天機器人接口分享

    小黃雞SimSimi是一個可愛的智能聊天機器人,他能和用戶進行有趣的對話,本文主要介紹了php版小黃雞simsimi接口使用的示例,大家參考使用吧
    2014-01-01
  • PHP cURL初始化和執(zhí)行方法入門級代碼

    PHP cURL初始化和執(zhí)行方法入門級代碼

    這篇文章主要介紹了PHP cURL初始化和執(zhí)行方法入門級代碼,本文直接給出代碼示例,代碼中包含詳細注釋,需要的朋友可以參考下
    2015-05-05
  • 如何在Laravel之外使用illuminate組件詳解

    如何在Laravel之外使用illuminate組件詳解

    這篇文章主要給大家介紹了關(guān)于如何在Laravel之外使用illuminate組件的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-09-09
  • 簡單示例AJAX結(jié)合PHP代碼實現(xiàn)登錄效果代碼

    簡單示例AJAX結(jié)合PHP代碼實現(xiàn)登錄效果代碼

    比較簡單的通過ajax+php實現(xiàn)登陸功能,這是個簡單的例子,固定字符,實際應用中可以從數(shù)據(jù)庫中讀取
    2008-07-07
  • PHP實現(xiàn)linux命令tail -f

    PHP實現(xiàn)linux命令tail -f

    tail 命令從指定點開始將文件寫到標準輸出.使用tail命令的-f選項可以方便的查閱正在改變的日志文件,tail -f filename會把filename里最尾部的內(nèi)容顯示在屏幕上,并且不但刷新,使你看到最新的文件內(nèi)容.接下來通過本文給大家介紹PHP實現(xiàn)linux命令tail -f,需要的朋友參考下
    2016-02-02
  • thinkPHP框架樂觀鎖和悲觀鎖實例分析

    thinkPHP框架樂觀鎖和悲觀鎖實例分析

    這篇文章主要介紹了thinkPHP框架樂觀鎖和悲觀鎖,結(jié)合實例形式分析了框架樂觀鎖和悲觀鎖的原理及thinkPHP相關(guān)實現(xiàn)技巧,需要的朋友可以參考下
    2019-10-10
  • 詳解PHP中strlen和mb_strlen函數(shù)的區(qū)別

    詳解PHP中strlen和mb_strlen函數(shù)的區(qū)別

    在PHP中,strlen與mb_strlen是求字符串長度的函數(shù),但是對于一些初學者來說,如果不看手冊,也許不太清楚其中的區(qū)別
    2014-03-03
  • PHP輸出緩沖控制Output Control系列函數(shù)詳解

    PHP輸出緩沖控制Output Control系列函數(shù)詳解

    這篇文章主要介紹了PHP輸出緩沖控制Output Control系列函數(shù)詳解,本文講解了輸出緩沖的簡介、輸出緩沖的作用、php.ini 中的相關(guān)配置項、Output Control 函數(shù)詳解等內(nèi)容,需要的朋友可以參考下
    2015-07-07
  • PHP中字符與字節(jié)的區(qū)別及字符串與字節(jié)轉(zhuǎn)換示例

    PHP中字符與字節(jié)的區(qū)別及字符串與字節(jié)轉(zhuǎn)換示例

    在php中字符是可使用多種不同字符方案或代碼頁來表示的抽象實體。字節(jié)是通過網(wǎng)絡傳輸信息(或在硬盤或內(nèi)存中存儲信息)的單位。本文還通過實例給大家介紹了php中字符串與字節(jié)轉(zhuǎn)換示例,感興趣的朋友一起看看吧
    2016-10-10
  • SSO單點登錄的PHP實現(xiàn)方法(Laravel框架)

    SSO單點登錄的PHP實現(xiàn)方法(Laravel框架)

    這篇文章主要介紹了SSO單點登錄的PHP實現(xiàn)方法(Laravel框架) 的相關(guān)資料,需要的朋友可以參考下
    2016-03-03

最新評論