简体   繁体   English

如何使用批处理文件修改所有文件和子目录的时间戳(最近修改)

[英]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.

相关问题 如何在批处理文件中回显文件的最后修改时间? - How can I echo a files last modified time in a batch file? 如何使用Windows XP的批处理脚本列出所有子目录中的所有隐藏文件? - How can i list all hidden files inside all subdirectories using batch scripting for windows XP? 如何编写批处理文件以归档位于子目录中的文件? - How can I write batch file for archiving files being in subdirectories? 如何在Windows批处理脚本中检查文件的时间戳创建? - How can I check the time stamp creation of a file in a Windows batch script? 获取使用批处理在上周修改的所有文件的文件名? - Getting the file names of all the files that were modified in the last week using batch? 使用批处理文件,如何删除不在Windows目录中的所有文件? - using a batch file, how can i delete all files not in the windows dir? 使用批处理文件监视文件夹的上次修改时间 - monitor last modified time for a folder using batch file 使用批处理文件列出过去 7 天内创建或修改的文件 - Using batch file to list files created or modified in the last 7days 用于更新所有文件的批处理文件已修改和访问的日期和时间 - Batch file to update all files Modified and Accessed Date and Time Windows批处理文件 - 连接子目录中的所有文件 - Windows batch file - Concatenate all files in subdirectories
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM