Solved

Can't delete empty directory

Posted on 1998-02-13
2
597 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Does Microsoft Office 2016 support COM/ActiveX? 3 84
Visual Studio 2015 vs. Visual Studio 2010 9 64
Problem to adjust sheet 1 86
What is MicroStrategy.NET? 2 58
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now