Keystone Jack
Keystone Jack

Reputation: 309

Original filename in node

Is it possible to get original filename from a file with an absolute path in node?

For instance, in node I can get the name and base url with path.basename and more detailed info with fs.stats, which will result in:

Stats {
  dev: 2114,
  ino: 48064969,
  mode: 33188,
  nlink: 1,
  uid: 85,
  gid: 100,
  rdev: 0,
  size: 527,
  blksize: 4096,
  blocks: 8,
  atimeMs: 1318289051000.1,
  mtimeMs: 1318289051000.1,
  ctimeMs: 1318289051000.1,
  birthtimeMs: 1318289051000.1,
  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 }

None of these method however will give me the original name of the file, which is useful for comparing 2 files to each other. For instance, if I download a file called file.exe from some website and then download the same file again, the new file will be called file (1).exe and has therefore not the same name as original.

Because of this I can't compare the filenames to each other.

Anyone know a good solution?

Upvotes: 1

Views: 725

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074295

For instance, if I download a file called file.exe from some website and then download the same file again, the new file will be called file (1).exe and has therefore not the same name as original.

In the general case, the name of the file is not stored in the file data anywhere, so if you've downloaded the file as file (1).exe, you have no way of knowing that it was called file.exe at some point in the past.

In the specific case of an .exe file, some name may or may not be somewhere in the file's contents, but it's not necessarily the name it most recently had before you renamed it.

Upvotes: 1

Related Questions