Cleaning and bulk delete the log file

As a developer, a line of code farmers, when we write programs often bring their own programs add a lot of log output, which is a good habit, but many programmers did not increase the log periodic removal of the program which is good habit, more than a decade in the IT field, access to the software is also varied, this is a common problem has been suffering operation and maintenance personnel, in general, customers will have the operation and maintenance system, it will set up server disk space warning, less than once how much space it will remind maintenance staff to delete the log.

There are some online batch command, you can delete these logs, then add the task to plan the timing of execution inside, it's a way I described here do not do, little interested partners can own Baidu.

I have presented here is a more extreme case I encountered, a service, running for a year without any problems, suddenly one day to die, after inspection found the service to write the log disk is full. Then ready to delete files, folders mess result, many types of log files, delete do not know what is good, the most terrible is that right attributes looked at these small log files actually reached one million I le a Boy, this is terrible, and delete with the delete key, leading to the death card interface, and are unable to recover the kind of response.

Try a lot of ways, not stuck is accidentally deleted.

Way of thinking is that farm operation code on the computer are possible to achieve by way of a program, and thus be open to dry.

General approach is to obtain a disk file:

The Directory.GetFiles ( " folder path " , " document type " , SearchOption.AllDirectories);

This is a common method above, but is not applicable under this scenario, once using the above methods, direct and press the Delete key to delete the same system, the program stuck. Put another writing

The dir = the DirectoryInfo new new the DirectoryInfo ( " folder path " ); 
the FileInfo [] Files = dir.GetFiles (); 
the DirectoryInfo [] dirs = dir.GetDirectories ();

With the above in this way, combined with recursion or through the bad, digression in general are all recursive loop can be written to achieve (interested in small partner can own Baidu, I will not explain here)

Through the layers of recursion, get all the information and documents folder information, so that you can delete these files.

Program interface as follows:

Features: Set delete a folder, and then analyze folder, analyze the distribution of file folders can understand folder

By analyzing the folder the size of various file types, as well as to determine the number, which is required to delete files

Other features not presented here focus on what e-mail notification, because of the need to delete files very, very much, delete consuming may take several hours or even days, thereby increasing a notification message is already deleted.

 

Guess you like

Origin www.cnblogs.com/huangyoulong/p/12624244.html