user5049440
user5049440

Reputation:

Electron: Is it possible to retrieve the date and time that a file last accessed

For those of you that use Electron to build desktop apps. Is it possible to retrieve the last access time of executable files on Windows or Mac and how is this done? In C++ one can use the GetFileTime function, how can someone do this in an Electron app?

Upvotes: 2

Views: 1683

Answers (1)

DavidTheWin
DavidTheWin

Reputation: 208

Electron allows use of the Node API meaning the best way to access the file system is to use fs. In particular, the fs.Stats class described here https://nodejs.org/api/fs.html#fs_class_fs_stats

You can use fs.stat to get the fs.Stats object for the file you want

fs.stat("path/to/file.exe", (err, stats) => someFunction(err, stats));

Where someFunction checks the returned fs.Stats object for the relevant data. The API link above says that the atime, mtime, ctime, and birthtime properties of the stats object representing access time, modified time, changed time, and creation time respectively.

Upvotes: 1

Related Questions