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)?