Detecting moved files using FileSystemWatcher

后端 未结 6 695
面向向阳花
面向向阳花 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:07

    StorageLibrary class can track moves. The example from Microsoft:

    StorageLibrary videosLib = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);
    StorageLibraryChangeTracker videoTracker = videosLib.ChangeTracker;
    videoTracker.Enable();
    

    A complete example could be found here. However, it looks like you can only track changes inside Windows "known libraries".

    You can also try to get StorageLibraryChangeTracker using StorageFolder.TryGetChangeTracker(). But your folder must be under sync root, you can not use this method to get an arbitrary folder in file system.

提交回复
热议问题