How to identify whether folder is opened?

后端 未结 3 1476
小鲜肉
小鲜肉 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:03

    It is not reasonable to determine if a program has a folder open in such a way that prevents you from renaming it. Because immediately after you make the determination, another process could start or stop using the folder. Instead just do the operation and catch the resulting exception.

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

提交回复
热议问题