更改目录时间/日期

发布于 2024-12-06 11:56:56 字数 365 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在你怀里撒娇 2024-12-13 11:56:56

对于 Windows,您可以使用 SetFileTime 也适用于目录。

For Windows you can use the SetFileTime which also works for directories.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文