none
Detect what files have changed RRS feed

  • Question

  • Hello,

     I'm trying to monitor a single directory and retrieve information about the files that have been changed. I would use a FileSystemWatcher object, but I need to detect change between when the app was last run and is currently run. The FSW only works at runtime. I came across the Sync framework which seems to be what I need, but it seems that I need to have a separate source and destination. I don't want to directly sync my objects, I just want to retrieve the files that have changed and perform a few custom actions on them. What's the best way of doing this? I tried setting the source and destination to the same FileSyncProvider, but got an exception saying that a synchronization was already in progress.

    What's the best way of detecting which files have changed?

    Thanks

    Sunday, September 30, 2012 2:01 AM

All replies

  • just create a dummy destination folder, then have it detect the changes in Preview mode.

    • Marked as answer by MolemanH Tuesday, October 2, 2012 3:39 PM
    • Unmarked as answer by MolemanH Thursday, October 4, 2012 1:58 AM
    Tuesday, October 2, 2012 1:24 AM
    Moderator
  • Thank you, I hadn't realised there was a preview mode. I figured I could cancel on the ApplyingChanges event but that seemed like a hack.
    Tuesday, October 2, 2012 3:39 PM
  • I tried the preview mode method but it has a couple of problems. Because nothing is copied over, the ApplyingChangeEventArgs.CurrentFileData is always null. This means that I don't know the name of the file that was modified, only the new name whereas I need to know the old name and the new one. The other problem is also related to the fact that nothing is copied over, the number of changed files accumulate. After one file has changed, it runs once. If I run it again, it runs once for the first file then again for the new one. I might be missing something obvious as I've never used the framework before.
    • Edited by MolemanH Thursday, October 4, 2012 2:05 AM
    Thursday, October 4, 2012 2:03 AM