简体   繁体   中英

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. 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

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM