how to delete an non-empty directory
-
Can someone tell me how to easily delete a non-empty directory. I am aware of the 'RemoveDirectory' api but it states in its documentation that it only deletes an empty directory. Is there an easy way to do this. I was thinking of using the ShellExecutre API and calling the 'RD' or 'RMDIR' dos commands, but I cant path to these programs. Thank you.
-
Can someone tell me how to easily delete a non-empty directory. I am aware of the 'RemoveDirectory' api but it states in its documentation that it only deletes an empty directory. Is there an easy way to do this. I was thinking of using the ShellExecutre API and calling the 'RD' or 'RMDIR' dos commands, but I cant path to these programs. Thank you.
Why ShellExecute? You can use
system
, defined inprocess.h
I vote pro drink :beer: -
Can someone tell me how to easily delete a non-empty directory. I am aware of the 'RemoveDirectory' api but it states in its documentation that it only deletes an empty directory. Is there an easy way to do this. I was thinking of using the ShellExecutre API and calling the 'RD' or 'RMDIR' dos commands, but I cant path to these programs. Thank you.
-
Can someone tell me how to easily delete a non-empty directory. I am aware of the 'RemoveDirectory' api but it states in its documentation that it only deletes an empty directory. Is there an easy way to do this. I was thinking of using the ShellExecutre API and calling the 'RD' or 'RMDIR' dos commands, but I cant path to these programs. Thank you.
SHFileOperation() will do it. I have a wrapper class in the Shell section here on CP to make it easier to use, as well. --Mike-- http://home.inreach.com/mdunn/ "....." -- Silent Bob :love: your :bob: with :vegemite: and :beer:
-
Can someone tell me how to easily delete a non-empty directory. I am aware of the 'RemoveDirectory' api but it states in its documentation that it only deletes an empty directory. Is there an easy way to do this. I was thinking of using the ShellExecutre API and calling the 'RD' or 'RMDIR' dos commands, but I cant path to these programs. Thank you.
BOOL ClearDirectory(const char *path, BOOL recurs, BOOL deldirs) { if(!path) return FALSE; char xpath[512]=""; strcpy(xpath,path); HANDLE hFile; WIN32_FIND_DATA findData; BOOL Go=TRUE; char fullp[500]=""; char pattern[500]=""; if(xpath[strlen(xpath)-1]!='\\') strcat(xpath,"\\"); if(!IsDirectory(xpath)) return FALSE; strcpy(pattern,xpath); strcat(pattern,"*.*"); hFile=FindFirstFile(pattern,&findData); while((hFile!=INVALID_HANDLE_VALUE)&&(Go)) { if((strcmp(findData.cFileName,".")!=0)&&(strcmp(findData.cFileName,"..")!=0)) { strcpy(fullp,""); sprintf(fullp,"%s%s",xpath,findData.cFileName); if(IsDirectory(fullp)) { ClearDirectory(fullp,recurs,deldirs); strcat(fullp,"\\"); if(deldirs) RemoveDirectory(fullp); } else { SetFileAttributes(fullp,128); DeleteFile(fullp); } } ZeroMemory((void*)&findData,sizeof(findData)); Go=FindNextFile(hFile,&findData); } FindClose(hFile); if(deldirs) RemoveDirectory(xpath); return TRUE; } //rate me or hate I am the mighty keeper of the book on knowledge . Contact me to get your copy .