How to bulk clean up the system temp file (language: C #, C + +, PHP, Python, Java), _php tutorial

Source: Internet
Author: User
Tags echo date

How to bulk clean up the system temp files (languages: C #, C + +, PHP, Python, Java),


A long history of language, the following do some IO experiment (traverse 9G files, bulk delete), as far as possible to use the facts to compare who superior who inferior. Operating system: Win7 64-bit, file package size: 9.68G.

First, language: C #

Development environment: vs 2013

Total lines of code: 43 rows

Time: 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 directory to clean up:");p ath = Console.ReadLine ();//Start Timing Console.WriteLine ("Start Time:" +datetime.now.tostring (" HH:mm:ss "));//Iterate through the match lookup and then loop Delete if (directory.exists (path)) {Console.Write (" deleting "); foreach (String FileName in Directory.getfilesystementries (path)) {if (file.exists (fileName) && filename.contains ("Cachegrind.out")) { File.delete (FileName);}} Console.WriteLine ("");} Else{console.writeline ("The directory does not exist!");} Chronograph end Console.WriteLine ("End timing:" + DateTime.Now.ToString ("HH:mm:ss")); Console.readkey ();}}}

Run:


Second, language: C + +

Development environment: vs 2013

Total lines of code: 50 rows

Time: 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 directory to clean:" << end L;getline (CIN, strpath);//start timing SYSTEMTIME sys_time; Declaring variable getlocaltime (&sys_time); Set the variable value to local time printf ("Start timing:%02d:%02d:%02d\n", sys_time.whour,sys_time.wminute,sys_time.wsecond);// First, iterate through the matching lookup to remove namespace fs = Boost::filesystem;fs::p ath Full_path (Fs::initial_path ()); Full_path = Fs::system_complete ( FS::p Ath (strpath, fs::native)), if (Fs::exists (Full_path)) {cout << "deleting"; FS::d Irectory_iterator Item_begin ( Full_path) FS::d irectory_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;} Chronograph end Getlocaltime (&sys_time);p rintf ("Timing over:%02d:%02d:%02d\n", Sys_time.whour, Sys_time.wminute, Sys_time. Wsecond); system ("pause"); return 0;} 
       
      
     
    
   
  
 

Run:


Third, language: PHP

Development environment: Phpstorm

Total lines of code: 32 rows

Time: 13 seconds

Code:

<?php/*** Created by phpstorm.* user:administrator* date:16-1-29* time: Morning 9:31*/date_default_timezone_set (' PRC '); /input Directory E:\tmp$path = ' e:\tmp ';//Start timing echo Date ("H:i:s", Time ()). '
';//first traverse the match lookup to recycle delete if (Is_dir ($path)) {echo "is being deleted", $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!". '
';} Timing ends Echo Date ("H:i:s", Time ()). '

Run:


Iv. Language: Java

Development environment: Eclipse

Total lines of code: 43 rows

Time: 10 seconds

Code:

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);//input Directory E: \tmpstring path = null; System.out.println ("Enter directory to clean up:");p ath = S.next ();//Start Timing date nowtime=new date (); SimpleDateFormat time=new SimpleDateFormat ("HH:mm:ss"); System.out.println ("Start chronograph:" + Time.format (nowtime)); Loop through the matching lookup to remove the file dir = new file (path), and 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 lines of code: 20 rows

Time: 10 seconds

Code:

#-*-coding:utf-8-*-import datetimeimport os# input Directory E:\tmppath = input ("Enter directory to clean up: \ n"); # Start timing print ("Start time:", datetime.date Time.now (). Strftime ('%h:%m:%s ')) # First, loop through the matching lookup to recycle the IF (os.path.exists (path)):p rint ("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

Run:

Articles you may be interested in:

    • PowerShell Script Cleanup temporary folder implementation code before the specified number of days

http://www.bkjia.com/PHPjc/1098285.html www.bkjia.com true http://www.bkjia.com/PHPjc/1098285.html techarticle How to batch clean up the system temporary files (language: C #, C + +, PHP, Python, Java), the language of the struggle for a long-standing, below do some IO experiment (traverse 9G files, bulk delete), ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.