Discussion Locked

Batch file to move files based on date

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
We have a process that outputs multiple files throughout the day and we would like to have a batch file run at night to create a directory with the current date (format of the date isn't crucial). Then move the files made that day to the recently created directory. I have found old dos batch files but none work in Windows Server 2k3. Any help

7 replies

by rbmrf

makedir c:\backupdir\%date%

this will create a directory with the current date

the rest i think is easy move c:\* c:\backupdir\%date%

i use this for running backups at nigth, and my directories are with the date of the day that the script runs

by hardeec

I wish it was that simple. %date% outputs "Tue 06/14/05". It can't make a directory or copy files with "Tue 06/14/05". I either need a batch command that edits %date% down to a usable date or some other method. Any other ideas?

by tonythetiger

(Between the '===' is all on one line)
===
for /f "tokens=1-4 delims=/ " %%i in ('date /t') do set todaydir=%%l%%j%%k
===
then change to the destination drive and

md %todaydir%

look at help for date options for XCOPY. Move does not have a date function, but Xcopy does, you can then delete the files you just xcopied by going to the destination drive and directory and

for %%f in (*.*) do del [source directory]\%%f

by hardeec

bless you. It works! Where is this type of batch programing listed on microsoft's site? I am going to close the question so just send me a private message.

This discussion is closed to new replies.