您好,欢迎访问一九零五行业门户网

如何批量清理系统临时文件(语言:C#、 C/C++、 php 、python 、java ),_PHP教程

如何批量清理系统临时文件(语言:c#、 c/c++、 php 、python 、java ),语言之争由来已久,下面做一些io实验(遍历9g多的文件,批量删除),尽量用事实来比较谁优谁劣。操作系统:win7 64 位,文件包大小:9.68g。
一、语言:c#
开发环境:vs 2013
代码总行数: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));// 先遍历匹配查找再循环删除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();}}}
运行效果图:
二、语言:c/c++
开发环境:vs 2013
代码总行数:50行
耗时:36秒
代码:
#include #include #include #include #include #include #include using namespace std;int main(int argc, char * argv[]){// 输入目录 e:\tmpstring strpath;cout << 输入要清理的目录: 运行效果图:
三、语言:php
开发环境:phpstorm
代码总行数:32行
耗时:13秒
代码:
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秒
代码:
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)); // 先遍历匹配查找再循环删除file dir = new file(path);if(dir.exists()){system.out.print(正在删除);file[] fs = dir.listfiles();for(int i=0;i 运行效果图:
五、语言:python 3.3.5
开发环境:idle
代码总行数:20行
耗时:10秒
代码:
# -*- coding: utf-8 -*- import datetimeimport os# 输入目录 e:\tmppath = input(输入要清理的目录:\n);# 开始计时print(开始计时:,datetime.datetime.now().strftime('%h:%m:%s'));# 先遍历匹配查找再循环删除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'));
运行效果图:
您可能感兴趣的文章:powershell脚本清理指定天数前的临时文件夹实现代码
http://www.bkjia.com/phpjc/1098285.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1098285.htmltecharticle如何批量清理系统临时文件(语言:c#、 c/c++、 php 、python 、java ), 语言之争由来已久,下面做一些io实验(遍历9g多的文件,批量删除),...
其它类似信息

推荐信息