Solved

Can't delete empty directory

Posted on 1998-02-13
2
598 Views
Last Modified: 2013-12-03
I've created a function that will delete recursively a directory tree; well that is what it is suppose to do. I am able to delete all the files within the directoy tree but I cannot delete the directories.

Here is the part of the code that is not working:

/* First I store the address\name of the current directory*/
CurrentDir=FileInfo->cFileName;            

/* Then I set that directory as the current directory to search recursively*/
SetCurrentDirectory(FileInfo->cFileName);

/* Recursive function that deletes the files and directories under the current directory*/
SearchDirectory(FileInfo);

/* After it returns I go back to the previous directory */                              
SetCurrentDirectory("..");

/* Then I attempt to delete the directory */
RemoveDirectory(CurrentDir.GetBuffer(1))


The RemoveDirectory() function returns an:

ERROR_SHARING_VIOLATION

after I use GetLastError.


Is it that the directoy remains opened?

0
Comment
Question by:santamaria
2 Comments
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 1411239
Either that directory is the current directory for your process, or it is the current directory for some other process.  _any_ other process having a directory as the process current directory will prevent that directory from being deleted.

Check everything: the exploer, services, remote users logged into your machine.

Also, it's possible that you still have a file find handle open that's watching that directory. You didn't post all of your code, so I can't be more certain about that possibility.

.B ekiM


0
 

Author Comment

by:santamaria
ID: 1411240
Thanks, I was closing the FindFile handle at the wrong place.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

772 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