更改目录时间/日期
我在 Windows (XP) 和 Linux 上尝试了 utime()
。在 Windows 上,我收到 EACCES
错误,在 Linux 上,我没有收到任何错误(但时间未更改)。我的 utime()
代码很好,因为它适用于文件。我找不到 utime()
是否应该在目录上工作,但如果不是,我该如何更改时间和日期?
我正在寻找一种同时适用于 Windows 和 Linux 的解决方案,但如果不能,我始终可以使用一些操作系统特定的代码。
[编辑] 看来 utime 确实可以在 Linux 上工作,但它似乎对我不起作用,因为我正在移动该目录中的文件,并将时间戳更新为当前时间。
I tried utime()
on both Windows (XP) and Linux. On Windows I get an EACCES
error, on Linux I don't get any error (but the time is not changed). My utime()
code is fine, because it works on files. I could not find if utime()
is supposed to work on directories or not, but if not, how can I change the time and date?
I am looking for a solution that would ideally work for both Windows and Linux, but if not, I can always use some OS specific code.
[edit]
It seems that utime does indeed work on Linux, but it didn't appear to work for me because I was moving files in that directory, and that updated the time stamp to the current time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Windows,您可以使用 SetFileTime 也适用于目录。
For Windows you can use the SetFileTime which also works for directories.