Using batch file to move files in dos

November 1, 2011 at 12:31:02
Specs: Windows 7
Hi, I want to move files from one location on my computer to another location on my computer / server based on date modified. Also, I need to move these files to their respective folders month-wise. for ex: Files having modified date as 3rd March 2011 should be moved into a folder assigned for March files, say "March 2011". If the folder is not present in a particular location a new folder should be created with an appropriate name.

See More: Using batch file to move files in dos

Report •

#1
November 2, 2011 at 01:30:32
Please post your date format.


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


Report •

#2
November 2, 2011 at 17:51:43
My date format is mm-dd-yyyy

Report •

#3
November 2, 2011 at 22:09:56
Please test this, change paths to suit your requirements. Also change COPY to Move when you are satisfied that the script does what you want.

@echo off
cls
setlocal enabledelayedexpansion

set months=January February March April May June ^
July August September October November December

pushd Path\to\files\||Pushd failed - job terminated.&&exit /b

for /f "tokens=1-3*" %%1 in ('dir /od /tw ^|find "/"') do (
    set filedate=%%1&set month=!filedate:~0,2!&set year=!filedate:~-4!
    set file=%%4

if !month! lss 10 set month=!month:~-1!
call :monthsalpha

set newdir=!temp!\!monthalpha! !year!\
If not exist "!newdir!" md "!newdir!"
echo !file! being copied to !newdir!
COPY "!file!" "!newdir!">nul
)
exit /b

:monthsalpha
for /f "tokens=%month%" %%A in ("!months!") do (
    set monthalpha=%%A
)


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


Report •
Related Solutions


Ask Question