Solved

RemoveDirectory

Posted on 1998-07-07
5
797 Views
Last Modified: 2008-03-10
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.
 
0
Comment
Question by:jerm
5 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1167338
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.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1167339
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.
0
 
LVL 1

Accepted Solution

by:
alex_r earned 50 total points
ID: 1167340
This problem occurs when you are using non-Win32 findfirst and findnext
functions.

Use the following: FindFirstFile, FindNextFile, FindClose functions with WIN32_FIND_DATA struct.
Be sure to call the FindClose ! ! !

Then you can use RemoveDirectory function.
0
 

Author Comment

by:jerm
ID: 1167341
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
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167342
Actually, I believe I suggested that first.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ standard library based binary archive format 6 104
Dynamically allocate memory 9 62
max float value 3 51
Indy 10 not Receiving UDP broadcast 3 22
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question