批处理文件可以更改系统日期吗?保存带有属性的文件;将日期更改回当前日期?

发布于 2024-09-18 11:21:37 字数 417 浏览 1 评论 0原文

批处理文件可以更改系统日期吗?保存带有属性的文件;将日期更改回当前日期?

目标是使用批处理命令保存日期为 01-01-2010 的 MYFILE.TXT

我尝试设置 date=01-01-2010

然后保存文件,但它不起作用。

这不可能吗?

@echo off
rem to Run this Batch file as administrator

date 01-01-2010
echo %date%
pause
echo Hello World > test.txt

date 09-08-2010

echo %date%
pause

goto :eof

注意:如果我们没有“以管理员身份运行” 它会创建一条错误消息“客户端不拥有所需的权限”。

Can a batch file change the system date; save file with attributes; change date back to current date?

Goal to save MYFILE.TXT with the date of 01-01-2010

using Batch commands.

I have tried to set date=01-01-2010

and then save the file, but it didn't work.

Is this impossible?

@echo off
rem to Run this Batch file as administrator

date 01-01-2010
echo %date%
pause
echo Hello World > test.txt

date 09-08-2010

echo %date%
pause

goto :eof

Note: If we didn't "Run as Administrator"
It creates an error message of "A required privilege is not held by the client."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

不可一世的女人 2024-09-25 11:21:37

您最好的选择是从 GNUWin32 获取 touch 并使用来改变时间戳。通过更改系统日期来执行此操作就像使用大锤敲开坚果一样。

Your best bet is to probably grab touch from GNUWin32 and use that to change the timestamps. Doing this by changing the system date is like using a sledgehammer to crack a nut.

愿得七秒忆 2024-09-25 11:21:37

是的,批处理文件可以做到这一点,但我不推荐它。要在 Windows 中设置日期,可以使用 DATE 命令。要将日期设置为 01/01/2010,您可以在命令提示符处执行此命令:

date 01-01-2010

但是,您需要管理员权限才能使其工作。

要更改时间,命令是 TIME。

您可以使用帮助工具查找这两个命令。即

help date
help time

也可以使用批处理文件获取当前日期,以便您可以在进行更改后重新设置日期。这有点复杂。 这是一种方法

综上所述,我同意 Jack Kelly 的观点:获取一个 touch 实用程序。

Yes, a batch file can do it, but I wouldn't recommend it. To set the date in Windows, you use the DATE command. To set the date to 01/01/2010, you would execute this command at the command prompt:

date 01-01-2010

However, you will need administrator privileges in order for that to work.

To change the time, the command is TIME.

You can look up both commands by using the HELP facility. i.e.

help date
help time

It's also possible to get the current date using a batch file so that you can re-set the date after making your change. That's somewhat more complicated. Here's one way to do it.

All that said, I agree with Jack Kelly: get a touch utility.

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