【发布时间】:2017-03-29 02:42:09
【问题描述】:
对于那些使用 Electron 构建桌面应用程序的人。是否可以在 Windows 或 Mac 上检索可执行文件的最后访问时间,这是如何完成的?在 C++ 中,可以使用 获取文件时间 函数,有人怎么能在 Electron 应用中做到这一点?
【问题讨论】:
标签: windows macos electron file-access
对于那些使用 Electron 构建桌面应用程序的人。是否可以在 Windows 或 Mac 上检索可执行文件的最后访问时间,这是如何完成的?在 C++ 中,可以使用 获取文件时间 函数,有人怎么能在 Electron 应用中做到这一点?
【问题讨论】:
标签: windows macos electron file-access
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链接说stats对象的atime、mtime、ctime和birthtime属性分别代表访问时间、修改时间、更改时间和创建时间。
【讨论】: