[英]How can I can modify, using a batch file, the time stamp (last modified) of all files and subdirectories
I am looking to change the last modified time stamp of all my files and directories in "My documents". 我希望更改“我的文档”中所有文件和目录的最后修改的时间戳。 The reason is that all documents older than 3 months get deleted on the server I am using.
原因是所有超过3个月的文档都在我使用的服务器上被删除。 This is just a trick to keep my documents as I often need them again after a longer period of time.
这只是保留我的文档的一种技巧,因为长时间后我经常需要它们。
What I managed so far with the code below is to change the time stamp "last modified" of all files, including in the subdirectories. 到目前为止,我使用下面的代码管理的是更改所有文件(包括子目录中)的“上次修改”时间戳。 But it doesn't change the time stamp of the subdirectories themselves.
但这不会更改子目录本身的时间戳。
@echo off
for /f "delims=" %%a in ('dir /ad /b /s') do (
pushd "%%a"
copy /B /Y *.*+,,
popd
)
I got this piece of code after some research, but do not understand it fully... I hope you guys can help 经过一些研究,我得到了这段代码,但并没有完全理解...希望大家能提供帮助
I have solved it with the following code. 我已经用下面的代码解决了。 As @aschipfl suggested, I created a random file and then immediately deleted it afterwards
如@aschipfl所建议,我创建了一个随机文件,然后立即将其删除
@echo off
copy /B /Y *.*+,, >nul
echo. > randomfile.txt
if exist randomfile.txt del randomfile.txt /Q
for /f "delims=" %%a in ('dir /ad /b /s') do (
pushd "%%a"
copy /B /Y *.*+,, >nul
echo. > randomfile.txt
if exist randomfile.txt del randomfile.txt /Q
popd
)
cls
echo All files and folders updated %date% %time%
pause
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.