VC implementation of Bulk Delete the specified file method _c language

Source: Internet
Author: User

The example described in this article mainly realizes the deletion of a file at a specified location under a letter, which can be txt, doc, JPEG, and so on, as long as the selected format, and then define a good letter, you can delete all the specified types of files. Once again, please confirm before deleting, and cannot be recovered after deletion.
The following are the main core codes, and other code readers can add them themselves.

Shfileinfo Shinfo;
memset (&shinfo,0,sizeof (shfileinfo)); Himagelist himage = (himagelist) shgetfileinfo ("c:\\", 0,&shinfo, sizeof (shfileinfo), Shgfi_sysiconindex |
Shgfi_smallicon); 
M_imagelist.attach (Himage);
M_comboex.setimagelist (&m_imagelist);
M_comboex.resetcontent ();
Char pchdrives[128] = {0};
char* pchdrive; GetLogicalDriveStrings (sizeof (pchdrives), pchdrives);
Enumerate disk characters pchdrive = pchdrives;
int nitem = 0;
 while (*pchdrive) {Comboboxexitem CBI;
 CString Cstext; Cbi.mask = cbeif_image| Cbeif_indent|
   cbeif_overlay| cbeif_selectedimage|
 Cbeif_text; Shfileinfo Shinfo;
 Define file information int nicon; Shgetfileinfo (pchdrive, 0, &shinfo, sizeof (shinfo), shgfi_icon| Shgfi_smallicon);
 Get system file Icon Nicon = Shinfo.iicon;
 Setting Comboboxexitem structure Cbi.iitem = Nitem;
 Cbi.psztext = pchdrive;
 Cbi.cchtextmax = strlen (pchdrive);
 Cbi.iimage = Nicon;
 Cbi.iselectedimage = Nicon;
 Cbi.ioverlay = 0; 
 Cbi.iindent = (0 & 0x03); M_comboex.insertitem (&CBI); Inserting Data Nitem++;
 Pchdrive + = strlen (pchdrive) + 1; return TRUE; Return TRUE unless your set the focus to a control} void Cdeletedlg::onsyscommand (UINT NID, LPARAM LPARAM) {if (NID
 & 0xfff0) = = Idm_aboutbox) {CAboutDlg dlgabout;
 Dlgabout.domodal ();
 else {Cdialog::onsyscommand (NID, LParam); } void Cdeletedlg::onpaint () {if (Isiconic ()) {CPAINTDC DC (this);//device context for painting SendMessage (wm_i Conerasebkgnd, (WPARAM) DC.
 GETSAFEHDC (), 0);
 Center icon in client rectangle int cxicon = GetSystemMetrics (Sm_cxicon);
 int cyicon = GetSystemMetrics (Sm_cyicon);
 CRect rect;
 GetClientRect (&rect); int x = (rect.
 Width ()-Cxicon + 1)/2; int y = (rect.
 Height ()-Cyicon + 1)/2; Draw the icon DC.
 DrawIcon (x, y, M_hicon);
 else {cdialog::onpaint (); } hcursor Cdeletedlg::onquerydragicon () {return (hcursor) M_hicon;} void Cdeletedlg::D elfile (CString path,cstring nam
 e) {CString strtemp; if (path. Right (1)!= "\ \")//determine if the path ends with \ strtemp. Format("%s\\*.*", path);/Set wildcard character else strtemp.
 Format ("%s*.*", path);//Set wildcard character CFileFind FindFile; BOOL bfind = FindFile. FindFile (strtemp);/lookup file while (bfind)//Loop lookup {bfind = FindFile. FindNextFile ()//finds the next file if (!findfile. Isdots () &&!findfile. Isdirectory ()) {CString str = findfile.
  GetFileName (); int index = str.
  Reversefind ('. '); if (str. Right (str. GetLength ()-index) = = name) {DeleteFile (findfile.
  GetFilePath ()); } else if (FindFile.
 Isdots ()) {continue; else if (findfile. Isdirectory ())//If this is the directory {delfile (findfile). GetFilePath (), name);//Recursive lookup}} void Cdeletedlg::onbutdelete () {//Todo:add your control notification handler code
 Here CString Path,name;
 M_comboex.getwindowtext (path);
 M_exname.getwindowtext (name);/Get File extension delfile (path,name); MessageBox ("The specified type of file has been deleted!") ");
}

This eliminates the form part of the code, the VC development friends should be able to understand.

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.