user2516837
user2516837

Reputation:

Is there any way to retrieve a file / folder's unique ID via NodeJS?

The problem I face is simple. I want to keep track of the file/folder even after it has been renamed / deleted etc? Does NodeJS provide a way to access this information a file? I've tried the default file system module fs.stats() : https://nodejs.org/api/fs.html#fs_class_fs_stats . Unfortunately, it does not seem to provide such unique ID referencing for a particular file.

Does there exist such a solution in NodeJS?

Note: I DO NOT want to generate a Unique ID for a file. It's pretty easy to assign a random string to a file and associate the string with this this. But it's the other way around. I want to associate a file with a system wide string of some sort.

Any help is appreciated.

Upvotes: 6

Views: 3826

Answers (1)

Ratan Kumar
Ratan Kumar

Reputation: 1650

Looking at the link https://nodejs.org/api/fs.html#fs_class_fs_stats

Stats {
  dev: 2114,
  ino: 48064969,
  mode: 33188,
  nlink: 1,
  uid: 85,
  gid: 100,
  rdev: 0,
  size: 527,
  blksize: 4096,
  blocks: 8,
  atime: Mon, 10 Oct 2011 23:24:11 GMT,
  mtime: Mon, 10 Oct 2011 23:24:11 GMT,
  ctime: Mon, 10 Oct 2011 23:24:11 GMT,
  birthtime: Mon, 10 Oct 2011 23:24:11 GMT }

I can see unix inode number.

Can two files have the same inode number?

Two files can have the same inode, but only if they are part of different partitions. Inodes are only unique on a partition level, not on the whole system.

Thus, in addition to the inode number one also compares the device number.

var uniqueFileId[fileName] = (Stats.dev + Stats.ino)

Upvotes: 8

Related Questions