How to batch clear temporary system files (languages: C #, CC ++, php, python, and java ),. How to batch clear temporary system files (languages: C #, CC ++, php, python, and java, i/O experiments (traversing files larger than 9 GB and deleting files in batches) and how to batch clear temporary system files (languages: C #, C/C ++, php, python, and java ),
Language competition has been around for a long time. I will do some I/O experiments (traverse more than 9 GB files and delete them in batches) below to compare who is better and who is worse with the facts. OS: win7 64-bit, file package size: 9.68 GB.
I. language: C #
Development Environment: V. S. 2013
Total number of lines of code: 43
Time consumed: 7 seconds
Code:
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) {// input directory e: \ tmpstring path; Console. writeLine ("Enter the directory to be cleared:"); path = Console. readLine (); // start the timer Console. writeLine ("Start time:" + DateTime. now. toString ("HH: mm: ss"); // traverse and match to find and recycle and delete if (Directory. exists (path) {Console. writ E ("deleting"); foreach (string fileName in Directory. getFileSystemEntries (path) {if (File. exists (fileName) & fileName. contains ("cachegrind. out ") {File. delete (fileName) ;}} Console. writeLine ("");} else {Console. writeLine ("this directory does not exist! ");} // Time end Console. writeLine ("End time:" + DateTime. now. toString ("HH: mm: ss"); Console. readKey ();}}}
Run:
2. language: C/C ++
Development Environment: V. S. 2013
Total number of lines of code: 50
Time consumed: 36 seconds
Code:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; int main (int argc, char * argv []) {// input directory e: \ tmpstring strPath; cout <"Enter the directory to be cleared: "<endl; getline (cin, strPath); // start timing SYSTEMTIME sys_time; // declare the variable GetLocalTime (& sys_time ); // Set the variable value to the local time printf ("Start time: % 02d: % 02d: % 02d \ n", sys_time.wHour, sys_time.wMinute, sys_time.wSecond ); // traverse and match search first, find and recycle and delete namespace fs = boost: filesystem; fs: path full_path (fs: initial_path (); full_path = fs: system_com Plete (fs: path (strPath, fs: native); if (fs: exists (full_path) {cout <"deleting"; 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 <"this directory does not exist! "<Endl ;}// time end GetLocalTime (& sys_time); printf (" Time End: % 02d: % 02d: % 02d \ n ", sys_time.wHour, sys_time.wMinute, sys_time.wSecond); system ("pause"); return 0 ;}
Run:
III. language: PHP
Development Environment: Phpstorm
Total number of lines of code: 32
Time consumed: 13 seconds
Code:
<? Php/*** Created by PhpStorm. * User: Administrator * Date: 16-1-29 * Time: */date_default_timezone_set ('prc'); // enter the directory e: \ tmp $ path = 'E: \ tmp '; // start timing echo date ("H: I: s", time ()).'
'; // Search, Find, recycle, delete, if (is_dir ($ path) {echo "deleting"; $ mydir = dir ($ path ); while ($ file = $ mydir-> read () {if (file_exists ("$ path/$ file") & strpos ($ file, 'cachegrind. out') = 0) {unlink ("$ path/$ file") ;}} echo'
';} Else {echo "this directory does not exist! ".'
';} // Time End echo date ("H: I: s", time ()).'
';
Run:
4. language: Java
Development Environment: eclipse
Total number of lines of code: 43
Time consumed: 10 seconds
Code:
Package com. yejing; import java. io. file; import java. text. simpleDateFormat; import java. util. date; import java. util. role; public class Test {public static void main (String [] args) {s = new role (System. in); // input directory e: \ tmpString path = null; System. out. println ("Enter the directory to be cleaned:"); path = s. next (); // start timing Date nowTime = new Date (); SimpleDateFormat time = new SimpleDateFormat ("HH: mm: ss"); System. out. println ("start timing:" + time. format (nowTime); // first traverse and match to find and recycle delete File dir = new File (path); if (dir. exists () {System. out. print ("deleting"); File [] fs = dir. listFiles (); for (int I = 0; I
Run:
V. language: Python 3.3.5
Development Environment: IDLE
Total number of lines of code: 20
Time consumed: 10 seconds
Code:
#-*-Coding: UTF-8-*-import datetimeimport OS # input directory e: \ tmppath = input ("input directory to be cleaned: \ n "); # Start Time print ("Start time:", datetime. datetime. now (). strftime ('% H: % M: % S'); # traverse and match to find and recycle and delete if (OS. path. exists (path): print ("deleting"); 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 ("this directory does not exist! "); # Print (" End time: ", datetime. datetime. now (). strftime ('% H: % M: % S '));
Run:
Articles you may be interested in:
- PowerShell script to clear the temporary folder implementation code a specified number of days ago
Pipeline (language: C #, C/C ++, php, python, java), Language Competition for a long time, the following I/O experiments (traversing more than 9g files, batch delete ),...