How to determine if a folder is open?

In my application, I am trying to rename a folder, but if the folder is open in Windows Explorer, I get IOException. How to determine if a folder is open in Windows Explorer in C #?

+5
source share
3 answers

to catch an IOException?

As others have said, just try to do what you want, catch an exception if that happens, and take appropriate action no matter what is in your context.

You really don't have much choice, as I see it, think:

bool iHaveAccess = CheckAccess(folder);
if (iHaveAccess)
{
    RenameFolder(folder,newFolderName);
}

What happens if something else locks the folder between CheckAccess and the RenameFolder call? What are you going to do?

+8

, , . , , . .

try {
  Directory.Move("old","new");
  return true;
} catch ( IOException ) {
  return false;
}
+1

, , , . , .

0
source

All Articles