Delete all files in a folder and subfolder?

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
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
I figured that out, stupid me.. thanks anyways
Topic archived. No new replies allowed.