make folder, name it current date, copy files to it

July 31, 2012 at 22:34:38
Specs: Windows server 2008 R2 Standard
Hello all!

I am trying to automate a daily process to create a new folder named as the current date, (ie: 08012012) on a remote server via a mapped drive and copy files to that new folder for backup purposes.

I have figured out how to create the new folder and name it by date by researching, but I can't for the life of me get the batch file to copy the files INTO the new folder!

Here's what I have so far...

for /F "tokens=2-4 delims=/- " %%A in ('date/T') do md %%A%%B%%C
xcopy "d:\lw\*.* "%DATESTAMP%" /E /C /I /H /Q

It creates the directory, but it fails from that point on!

Any help would be greatly appreciated!



See More: make folder, name it current date, copy files to it

Report •

August 1, 2012 at 05:42:38
Run the batch file in a command prompt window. It will stay open and give you an error. My inclination is that it's failing with the xcopy command and it will be easier to see why its failing with its output message.

Andrew Leonard
BL Technical Services
IT Support Maryland

Report •

August 1, 2012 at 09:49:39
Thanks for the reply!

What is happening is, it's copying the file to the root of the folder that the new dated folder was created in instead of copying them INTO the dated folder.

I think what I am missing is how do I make the xcopy command identify the new folder the batch file created in order to copy the files into it? The folder name will change every day as the date changes, so I need the batch file to identify the current folder in order to know where to copy the files to.

I hope that makes sense!

Does that help?


Report •

August 6, 2012 at 11:41:30
You never set %DATESTAMP%.

@echo off
for /F "tokens=2-4 delims=/- " %%A in (
) do (
md %%A%%B%%C && pushd %%A%%B%%C
xcopy "d:\lw\*.*" "." /E /C /I /H /Q

Report •
Related Solutions

Ask Question