0

Given a path, I want to record the folder’s unique characteristics, so that next time I check these characteristics, I can tell if the folder has been changed or not.

The solution I can think of is to recursively record all the files’ path and checksum in string, and then calculate the checksum of the string.

I wonder if there’s more efficient way to do this.

Tom
  • 118
  • 1
  • 6
  • 1
    Sounds good. Might worth having a look into nodemon or other bulletproof tools that do this. – Jonas Wilms Jul 22 '19 at 20:22
  • 1
    If your program is running in the background, you can [use a file watcher](https://stackoverflow.com/q/13695046/1247781). If not, you can use the `mtime` property to query for last modified time: https://stackoverflow.com/a/40943102/1247781 – FThompson Jul 22 '19 at 20:25
  • Here is the Node docs on an [FSWatcher](https://nodejs.org/docs/latest/api/fs.html#fs_class_fs_fswatcher) – Bibberty Jul 22 '19 at 20:28

1 Answers1

1

You could save some calculations by looking at the mtime of the files inside the folder instead of calculating their hash.

You'd still need to do it for all the files inside the folder, as altering a file does not update the mtime of the folder containing it.

niko
  • 360
  • 1
  • 7