Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify whether folder is opened?

In my application I'm trying to rename the folder, but if the folder is opened in Windows Explorer I get an IOException. How can I identify whether folder is opened in Windows Explorer in C#?

like image 688
Prashant Cholachagudda Avatar asked Jan 22 '10 15:01

Prashant Cholachagudda


1 Answers

catch the IOException?

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

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

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

what happens if between CheckAccess succeeding and calling RenameFolder something else locks the folder? Whatcha gonna do then?

like image 158
Sam Holder Avatar answered Sep 24 '22 14:09

Sam Holder