加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何批量清理系统临时文件(语言:C#、 C/C++、 php 、python 、j

发布时间:2020-12-12 21:19:23 所属栏目:PHP教程 来源:网络整理
导读:语言之争由来已久,下面做一些IO实验(遍历9G多的文件,批量删除),尽量用事实来比较谁优谁劣。操作系统:win7 64 位,文件包大小:9.68G。 一、语言:C# 开发环境:vs 2013 代码总行数:43行 耗时:7秒 代码: 运行效果图: 二、语言:C/C++ 开发环境:vs

语言之争由来已久,下面做一些IO实验(遍历9G多的文件,批量删除),尽量用事实来比较谁优谁劣。操作系统:win7 64 位,文件包大小:9.68G。

一、语言:C#

开发环境:vs 2013

代码总行数:43行

耗时:7秒

代码:

运行效果图:

二、语言:C/C++

开发环境:vs 2013

代码总行数:50行

耗时:36秒

代码:

#include #include #include #include #include #include using namespace std; int main(int argc,char * argv[]) { // 输入目录 e:tmp string strPath; cout << "输入要清理的目录:" << endl; getline(cin,strPath); // 开始计时 SYSTEMTIME sys_time; //声明变量 GetLocalTime(&sys_time); //将变量值设置为本地时间 printf("开始计时:%02d:%02d:%02dn",sys_time.wHour,sys_time.wMinute,sys_time.wSecond); // 先遍历匹配查找再循环删除 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:%02dn",sys_time.wSecond); system("pause"); return 0; }

运行效果图:

三、语言:PHP

开发环境:Phpstorm

代码总行数:32行

耗时:13秒

代码:

'; //先遍历匹配查找再循环删除 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 '
'; } else { echo "该目录不存在!" . '
'; } //计时结束 echo date("H:i:s",time()) . '
';

运行效果图:

四、语言:Java

开发环境:eclipse

代码总行数:43行

耗时:10秒

代码:

运行效果图:

五、语言:Python 3.3.5

开发环境:IDLE

代码总行数:20行

耗时:10秒

代码:

else:

运行效果图:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读