How to identify whether folder is opened?

后端 未结 3 1442
小鲜肉
小鲜肉 2021-01-18 14:57

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

3条回答
  •  走了就别回头了
    2021-01-18 15:13

    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?

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题