0

I'm looking for a way to identify files with nodejs that works even if the file name and/or file path is changed. I'm hoping for a cross-platform solution (or at least Mac and Windows; Linux would be nice).

I was first hopeful that ino (ie inode, returned with fs.stat(file)) could work as a unique file identifier. (Discussion of that here and here). But it looks like inode is not reliable on Windows (status unclear, renders in 64-bit), and even on Mac I have seen that a file's inode can change when saving changes to a file.

So I'd need something that is unique to a file, that does not change. What about birthtime (or birthtimeMs), returned from fs.stat?

This is when a file is created, down to the millisecond. It does not seem to change on Mac, and (maybe?) does not seem to change on Windows or Linux. (seems like Mac, Windows, and updated Linux support birthtimeMs.)

And birthtime would be unique to each file, so long as a user can only create one file at a time (at least more than 1 millisecond difference between file create times).

So, could birthtime be used as a unique file identifier on Mac and Windows (and maybe Linux too)?

SeanRtS
  • 1,005
  • 1
  • 13
  • 31
  • 1
    probably the only way to reliably check if 2 files are same is to match checksum, and that's what mostly done today. When you download a file sometimes they will give u a text value a md5, sha checksum of the file for you to verify if the file you have downloaded is same or not. same concept here. – Aritra Chakraborty Jul 31 '21 at 19:08
  • Thanks. I could be wrong, but to get a checksum of a file I need to read the file's whole content and then create a hash, correct? That probably would start eating up too much processing and time in my case. Is there anything wrong with using birthtimeMs as an id for a file, to track a file as it changes (gets saved, changes name, changes path, etc)? – SeanRtS Jul 31 '21 at 19:16

0 Answers0