How to test if a file is currently being written to

后端 未结 9 1648
野性不改
野性不改 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:31

    Use the System.IO.FileSystemWatcher to determine files that are changed.

    Open them in an exclusive reader (FileMode.Read) in make the copies, and catch the exception should this fail (because someone else has it open for writing).

提交回复
热议问题