对于那些使用 Electron 构建桌面应用程序的人。是否可以在 Windows 或 Mac 上检索可执行文件的最后访问时间,这是如何完成的?在 C++ 中,可以使用
获取文件时间
功能,有人怎么能在 Electron 应用程序中做到这一点?
最佳答案
Electron 允许使用 Node API,这意味着访问文件系统的最佳方式是使用 fs
.特别是 fs.Stats
此处描述的类https://nodejs.org/api/fs.html#fs_class_fs_stats
您可以使用 fs.stat
获取 fs.Stats
您想要的文件的对象
fs.stat("path/to/file.exe", (err, stats) => someFunction(err, stats));
在哪里
someFunction
检查返回的 fs.Stats
相关数据的对象。上面的 API 链接说 atime
, mtime
, ctime
, 和 birthtime
stats
的属性对象分别表示访问时间、修改时间、修改时间和创建时间。
关于windows - Electron:是否可以检索文件上次访问的日期和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40606063/