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!

Trouble Deleting a Directory in Windows NT 4.0 1

Status
Not open for further replies.

dbucak

Programmer
Oct 19, 2001
2
US
I need to delete a directory from within a MFC application. _rmdir(lpstrDir) doesn't seem to work. If I call strerror(errno) to see what the trouble is it returns "Permission Denied". However when I check the permissions on the directory, Everyone has Full Control. I can also remove the directory manually from a command prompt or through explorer. According to the documentation CFile::Remove won't work on a directory. system("rmdir c:\\dir") works, but it flashes an annoying DOS window. Is there some other way I can do this? Thanks.
 
Of course, as soon as I posted this I figured it out. I had used a CFileFind object to find and delete all the files in the directory and I forgot to Close it.
 
Well, maybe this is still of some use. More convenient in some cases are the Windows Shell functions. With SHFileOperation() for example you can delete a directory even if it's full, like so:

SHFILEOPSTRUCT fo;

ZeroMemory(&fo,sizeof(fo));
fo.wFunc = FO_DELETE;
fo.fFlags = FOF_NOCONFIRMATION;
fo.pFrom = "C:\\temp1\0\0";
int res = SHFileOperation(&fo);

Somehow this seems to me more fitting for a MFC App than C lib functions:) What's more, it'll pop up nice standard Windows confirmation boxes if you want. (FOF_NOCONFIRMATION suppresses them). :) Hope that this helped! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top