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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a directory...

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
Hello,

I am trying to delete a directory. However, the DeleteFile and unlink functions have not ceased to stop failing. I am using the Windows API function FindFileNext in a while statement to list all the available files in specified directoy (which happens to contain more directories). It is these directories that I want to delete. Am I not closing the handle somewhere? And Yes, the program did create these directories I am trying to delete.

Code:
[green]//This is the end of the code that circulates through a directory[/green]

FindClose(h);
CloseHandle(h);

[green]
The directory does exist and is the correct name.
Also, GetFileAttributes on the entry returns positive
[/green]

Record.Format("%s\\%s\\%s\\,blah,blah2,blah3);

_unlink(Record);
[blue]or[/blue]
DeleteFile(Record);

/**************
Me: When will the project be finished?
Them: What project?
Me: The one you have been working on for the last 3 years!
Them: Ohh, we can't finish it?
Me: Why?
Them: We don't know how to program...
 
MSDN:
The RemoveDirectory function deletes an existing empty directory.
Code:
BOOL RemoveDirectory(
  LPCTSTR lpPathName   // pointer to directory to remove
);
Include <windows.h>...
Avoid CloseHandle(), must be FindClose() only for a handle obtained from FindFirstFile(). Clear the directory contents before deleting (build file list then remove() them). Don't forget to delete subdirectories and its contents (recursively)...

It's a hard work (very well - it's a destructive op;)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top