Deleting all files in a folder

i am using the following code, to delete everything in a folder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
	stSHFileOpStruct.fAnyOperationsAborted = FALSE;
	int nFileDeleteOprnRet = SHFileOperation( &stSHFileOpStruct );
	delete []pszFrom;
	if( 0 != nFileDeleteOprnRet )
	{
		return 1;
	}
	return 0;
}

if the function is not able to delete a file due to some reason, it stops.. is there a way i can make it continue deleting files even if it cannot delete some files.. ie. skip files that cannot be deleted and carry on with the other files?
You can enumerate all the files/folders into a folder with FindFirstFile and FindNextFile. That way you will handle "undeletable" files by yourself.
thanks.
Topic archived. No new replies allowed.