Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help w/ robocopy syntax

Status
Not open for further replies.

icemel

MIS
Joined
Oct 17, 2005
Messages
463
Location
US
Hi,

I have a question about robocopy.

I have some backups that I want to copy from one destination to another. I want to be able to specify the file by name, so that it will ONLY copy that specific backup and no other files.

The problem is, the file name will be changing every day, as the date is part of the filename, for example:

MyBackupFile_2005_11_21

So, I need to be able to copy the file based on today's date. How can I build up a string in robocopy using year, month and day from the system in order to specify the correct file?

I guess what I am trying to find out is if this is possible.

Thanks!!
 
Use a command file (.bat) with the for command. Check help for the syntax. You can extract the different parts of the current date and create a string to append to your file name.

Something like:

FOR /F "tokens=2,3,4 delims=/ " %%I
in ('DATE /T') DO SET
date1=%%I/%%J/%%K

Strange place for this question, thou... :-)

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
With Robocopy it's easier than that. Use the "/MINAGE n" flag to move all files that are older than n days.

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top