I'm trying to delete a folder only if it's not empty. So I'm using Directory.Delete(strPath); for that. It throws an exception if folder is not empty. But I can't seem to figure out how to differentiate between that error and some other error (say, if the path was wrong, folder didn't exist, was inaccessible because of ACL, etc.)
I can do this with Win32 in a heartbeat, but I'm somewhat stumped in .NET.
Any ideas?
try
{
Directory.Delete(strPath);
}
catch (Exception ex)
{
//if(FolderWasNotEmpty){ all-good-not-an-error(); }
//else { show-error(); }
}
PS. I'm using .NET 3.5 for this project.