【问题标题】:Electron: Is it possible to retrieve the date and time that a file last accessedElectron:是否可以检索文件上次访问的日期和时间
【发布时间】:2017-03-29 02:42:09
【问题描述】:

对于那些使用 Electron 构建桌面应用程序的人。是否可以在 Windows 或 Mac 上检索可执行文件的最后访问时间,这是如何完成的?在 C++ 中,可以使用 获取文件时间 函数,有人怎么能在 Electron 应用中做到这一点?

【问题讨论】:

    标签: windows macos electron file-access


    【解决方案1】:

    Electron 允许使用 Node API,这意味着访问文件系统的最佳方式是使用 fs。特别是这里描述的fs.Statshttps://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对象的atimemtimectimebirthtime属性分别代表访问时间、修改时间、更改时间和创建时间。

    【讨论】:

      猜你喜欢
      • 2012-05-08
      • 1970-01-01
      • 2011-01-19
      • 2012-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-12
      • 2011-07-12
      相关资源
      最近更新 更多