Question

How can i detect if a file has been renamed?

I am using a Poll method and not the System File Watcher method.

Currently I can detect changes with the System.IO.File object via the LastWriteTime property (DateModifed in File Explorer). However, when the file is renamed, I cannot see any property such as date properties changing date.

How can I detect file renames using a poll method?

The funny thing is that the directory that the file resides in changes date on renaming a file.

Was it helpful?

Solution

I had to do this at one stage with a small group of files, in that case, I stored the filepaths of every file, as well as create-date and filesize every time I polled.

Then every subsequent poll, I was able to detect files that are now 'missing' from the last time I polled. Then, I would cross check time created and filesize to detect if some of the newer files match some of the missing files. If I get a match, I assume a rename.

Please note however, it may not be safe / 100% accurate; you may have multiple files with the same create date and filesize etc. In my case, it was use generated photographs, I was able to also check exif data as a final verification. Depending on your situation, you may have other pieces of data to verify against.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top