Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete all subfolders and files of a given folder

Status
Not open for further replies.

Robertus

Programmer
Feb 16, 2001
81
0
0
RO
Does anybody know how could I delete all subfolders and files of a given folder (with MFC)?

I would apreciate your help, thanks a lot!
 
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shellapi.h>
#include <iostream>

int DeleteFolderStruct( LPSTR lpzRoot )
{
SHFILEOPSTRUCT shellOp;

shellOp.hwnd =NULL;
shellOp.wFunc =FO_DELETE;
shellOp.pFrom =lpzRoot;
shellOp.pTo =NULL;
shellOp.fFlags=FOF_NOCONFIRMATION | FOF_SILENT;
shellOp.hNameMappings=0;
shellOp.lpszProgressTitle=NULL;

return SHFileOperation( &shellOp );
}


int main()
{
char* sDir=&quot;C:\\deleteTemp&quot;;

if( DeleteFolderStruct( sDir )==0 )
std::cout << sDir << &quot; was deleted.&quot; <<
std::endl;
else
std::cout << sDir << &quot; COULD NOT BE DELETED.&quot; <<
std::endl;

return 0;
}

It should be trivial to integrate this into an MFC app. Mike L.G.
mlg400@linuxmail.org
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top