Deleting folders is sometimes not an easy task, especially for folders extracted by boost. There are too many directories and files in the folder. It takes a long time to wait until the confirmation interface is displayed.
The ideal situation is that, after selecting this directory, I can immediately start to delete it. Then I can stand up and have a drink, or have a meal. When I come back, the world is already quiet.
Of course, when Windows 7 deletes a large directory, the speed is quite fast, and the computer speed is getting faster and faster. Writing code by yourself is purely a personal hobby and is not necessarily faster than deleting windows. This article only records the actual practice of this idea, so that you do not have to worry about it for a long time.
You can create a window to receive operations such as selecting directories. A new deleterunner is created and the directory path is passed to the delete function.
Class deleterunner {private string m_strroot; private int longdirnum = 0; Public deleterunner () {} public void Delete (string strpath) // external interface {m_strroot = strpath; _ Delete (strpath);} private void _ Delete (string strfolder) {// delete a long path, move the directory to the root directory, and then delete it, prevent Windows Error prompt if (strfolder. length >=160) {int Pos = strfolder. lastindexof ("\"); If (Pos =-1) {return ;}++ longdirnum; string strdestdir = m_strroot + "\" + longdirnum; directory. move (strfolder, strdestdir); _ Delete (strdestdir); return;} // delete all files in the directory string [] listfiles = directory. getfiles (strfolder); If (listfiles. length> 0) {for (INT Index = 0; index <listfiles. length; ++ index) {fileinfo Fi = new fileinfo (listfiles [Index]); FI. attributes = fileattributes. normal; // prevents the deletion of a file due to a read-only file. delete (listfiles [Index]) ;}// delete all directories under this directory, that is, recursively Delete string [] listfolders = directory. getdirectories (strfolder); If (listfolders. length> 0) {for (INT Index = 0; index <listfolders. length; ++ index) {_ Delete (listfolders [Index]) ;}// finally Delete the current directory. delete (strfolder );}}
If you delete a directory that is not empty in the United States, you will still encounter some problems, such as prompts such as "the directory is not empty", but the problem will be ignored.