Detecting moved files using FileSystemWatcher

后端 未结 6 694
面向向阳花
面向向阳花 2020-11-30 06:54

I realise that FileSystemWatcher does not provide a Move event, instead it will generate a separate Delete and Create events for the same file. (The FilesystemWatcher is wa

6条回答
  •  日久生厌
    2020-11-30 07:31

    As far as I understand it, the Renamed event is for files being moved...?

    My mistake - the docs specifically say that only files inside a moved folder are considered "renamed" in a cut-and-paste operation:

    The operating system and FileSystemWatcher object interpret a cut-and-paste action or a move action as a rename action for a folder and its contents. If you cut and paste a folder with files into a folder being watched, the FileSystemWatcher object reports only the folder as new, but not its contents because they are essentially only renamed.

    It also says about moving files:

    Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several OnChanged and some OnCreated and OnDeleted events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events.

提交回复
热议问题