How to test if a file is currently being written to

后端 未结 9 1735
野性不改
野性不改 2020-12-18 21:42

I have an application that must check a folder and read any files that are copied into it. How do I test if a file in that folder is currently being written to? I only want

9条回答
  •  遥遥无期
    2020-12-18 22:36

    When you open it with System.IO.File.OpenWrite(filename), it should throw IOException.

    So, in a try catch, the code being executed in the catch block should tell you the file was open.

提交回复
热议问题