Delete all files in a folder and subfolder?
Jul 15, 2012 at 12:23pm UTC
I have a folder called wamp in drive D, i want to delete all the files present inside this folder and inside its subfolders (without deleting the folders)..
i have made the following function that deletes the files in my folder "wamp" but it is not able to delete files in the subfolders.
here is my function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
int del( const char * csDeleteFolderPath_i )
{
int nFolderPathLen = strlen(csDeleteFolderPath_i);
TCHAR *pszFrom = new TCHAR[nFolderPathLen + 2];
strcpy(pszFrom, csDeleteFolderPath_i);
pszFrom[nFolderPathLen] = 0;
pszFrom[++nFolderPathLen] = 0;
SHFILEOPSTRUCT stSHFileOpStruct = {0};
stSHFileOpStruct.wFunc = FO_DELETE;
stSHFileOpStruct.pFrom = pszFrom;
stSHFileOpStruct.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR | FOF_SILENT | FOF_FILESONLY;
stSHFileOpStruct.fAnyOperationsAborted = FALSE;
int nFileDeleteOprnRet = SHFileOperation( &stSHFileOpStruct );
delete []pszFrom;
if ( 0 != nFileDeleteOprnRet )
{
return 1;
}
return 0;
}
Any help/suggestion would be appreciated.
i am sending this string to my function "d:\\wamp\\*.*"
Last edited on Jul 15, 2012 at 12:29pm UTC
Jul 17, 2012 at 5:39am UTC
In this line:
stSHFileOpStruct.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR | FOF_SILENT | FOF_FILESONLY;
You specified FOF_FILESONLY... I suggest you remove this if you want to delete the subfolders as well.
Last edited on Jul 17, 2012 at 5:40am UTC
Jul 17, 2012 at 9:12am UTC
I figured that out, stupid me.. thanks anyways
Topic archived. No new replies allowed.