Moving files based on last modified date

May 5, 2011 at 23:38:24
Specs: Windows XP
Greetings all,

i have 2 folders here: main and archive.

i would want to move files in the main folder, which those files that are 1 day old, to the archive folder.

hopefully you guys can help me with this. thanks!


See More: Moving files based on last modified date

Report •


#1
May 6, 2011 at 19:22:34
Test this, if you are satisfied with the output change Copy to Move. No warranties! Script expects your date separator to be / (forward slash), if it is some other option change the script to suit.

@echo off
setlocal 
cls

pushd main\||echo Pushd failed - job terminated.&&exit /b

set vbs=%temp%\vbs.vbs

> %vbs% echo WScript.Echo DateAdd("d",-1,Date)

for /f "tokens=*" %%a in ('cscript //nologo %vbs%') do set yesterday=%%a
del %vbs%

for /f "tokens=1-4* delims= " %%1 in ('dir /tw /a-d ^| find "/"') do (
    if "%%1 %%2" equ "%yesterday%" copy "%%5" archive\>nul
    )
popd


Please come back & tell us if your problem is resolved.


Report •

#2
May 8, 2011 at 19:58:55
Thank you for replying with solution. However, do you mind explain what each line does?

I am new to Batch coding.


Report •

#3
May 8, 2011 at 23:01:23
It would be best if you studied the commands which are available at http://ss64.com/nt/ then came back for an explanation of anything you do not understand.

Good luck.


Please come back & tell us if your problem is resolved.


Report •

Related Solutions


Ask Question