Joe Mamma
Well-known member
this is a recursive routine to delete empty sub directories under a given path.
Directory.Delete(Path.GetFileName(aPath))
gives error:
C:\Practice
|_ Sub1
I make a call DeleteEmpty("C:\Practice");
Sub1 is empty.
There is no process locking the path. While In debugging, I can manually delete the folder while the error message is up.
any ideas????
PHP:
private void DeleteEmpty(string aPath)
{
string currPath = System.Environment.CurrentDirectory;
System.Environment.CurrentDirectory = aPath;
string[] directory = Directory.GetDirectories(".");
string[] file = Directory.GetFiles(".");
if ((file.Length + directory.Length)==0)
{
System.Environment.CurrentDirectory = currPath;
Directory.Delete(aPath);
}
else
if (directory.Length>0)
for(int i = 0; i < directory.Length; i++)
DeleteEmpty(directory[i]);
else
System.Environment.CurrentDirectory = currPath;
}
Directory.Delete(Path.GetFileName(aPath))
gives error:
I have the directory structure:An unhandled exception of type System.IO.IOException occurred in mscorlib.dll
Additional information: Access to the path "C:\Practice\Sub1" is denied.
C:\Practice
|_ Sub1
I make a call DeleteEmpty("C:\Practice");
Sub1 is empty.
There is no process locking the path. While In debugging, I can manually delete the folder while the error message is up.
any ideas????
Last edited by a moderator: