So I created the below code to grab the YEAR of a file from the DATE MODIFIED and if it is NOT EQUAL to 2010, then move all the files in that DIR by creating a second .BAT. However, I have MANY sub-dirs, with MORE files, how can I have it go through ALL sub-dirs without having to code the sub dir each time.
echo off & setLocal EnableDELAYedExpansion
PUSHD Y:\DIR1\DIR2\
SET source=Y:\DIR1\SUBDIR1\
SET dest=”F:\DIR1\SUBDIR1\”
for /f “tokens=* delims= ” %%a in (‘dir/b/a-d’) do (
SET DATETIME=%%~Ta
for /f “tokens=1 delims=/: ” %%m in (“%%~Ta”) DO SET month=%%m
for /f “tokens=2 delims=/: ” %%d in (“%%~Ta”) DO SET day=%%d
for /f “tokens=3 delims=/: ” %%y in (“%%~Ta”) DO SET year=%%y
IF “!year!” NEQ “2010” (SET FILE=%%a)
IF “!year!” NEQ “2010” (>>”F:\MOVE.bat” ECHO MOVE /Y “!source!!FILE!” !dest! )
)
CALL “F:\MOVE.bat”
This in biterscripting. Here is how it works. The lf (list files – http://www.biterscripting.com/helpp… ) finds all files in $src directory (recursively in subfolders -r) whose file mod time is earlier than $date. The $newlocation is created by replacing $src with $dest in $file. Finally, each such $file is moved to corresponding $newlocation. Call the script as
i think both forward and backward slashes work in file paths.