Link to home
Start Free TrialLog in
Avatar of jerm
jerm

asked on

RemoveDirectory

In my application there are a series of directories creates, in which data is stored.
Example:
   MYDATA -
           |_ SRC_FILES
           |_ BINARY_FILES

As the data is processed, it is moved over to a file server (from within the application) and the directories are to be deleted.  To make sure that the directories are empty, I created a function which will delete all files matching a filter (i.e. \MYDATA\SRC\*.*).  I know that this delete function works, because when I look at the directory it is empty.  The problem lies in the RemoveDirectory function.  It will not delete the directory and returns a system code of 32 (The process cannot access the file because it is being used by another process. -> ERROR_SHARING_VIOLATION).  Is this just a problem with my code, or is this a common event?  Note: I call the DeleteFiles function immediately before I attempt RemoveDirectory.  I thought that since I was accessing the directory so soon before I attempted to remove it, that the system would not be updated with its lack-of-file status.  However I am not %100 sure about this.
 
Avatar of nietod
nietod

How are you finding files to delete?  Most likely the code you ae using is leaving the directory file open so you cannot delete the directory.
Did you change to another directory that will not be deleted after you delete all the files in the current directory? May be the directory to be deleted is still the current active directory. Just a wild guess.
ASKER CERTIFIED SOLUTION
Avatar of alex_r
alex_r

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jerm

ASKER

alex_r - You were right.  I just needed a wakeup call.  My DeleteFiles function used FindFirstFile and FindNextFile, but I neglected to add FindClose.  The funny thing is that I used FindClose in all other file searches in this application.  Thank you for pointing that out to me.

Until next time
jerm
Actually, I believe I suggested that first.