robocopy append date to copied filename

Using RoboCopy, is there a way to append something to the copied filenames?
I want to set up a backup system where it will back up a specific file, and append the day of the month to it so that I'll always have a month's worth of backups. I can get the day of the month, but how can I append it with RoboCopy?
Thanks!
LVL 10
etech0Asked:
Who is Participating?
 
MikeOM_DBAConnect With a Mentor Commented:
Then just use "copy" (not xcopy).
0
 
MikeOM_DBACommented:
Create destination directories for each day of the month:

Robocopy C:\Folder1 X:\Folder%THISDAY%

Open in new window

0
 
etech0Author Commented:
That would be very unwieldy. As it's only one file, I'd rather have them all in one folder. Do you know if that's possible?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
etech0Author Commented:
Maybe I'm better off using XCopy?
0
 
MikeOM_DBACommented:
If it's only one file, Xcopy may be better.
0
 
etech0Author Commented:
With Xcopy, can I specify the copied file's filename?
0
 
MikeOM_DBACommented:
Yes:

Windows 2000 and XP xcopy syntax

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/EXCLUDE:file1[+file2][+file3]...]
source	Specifies the file(s) to copy.
destination	Specifies the location or name of new files.

Open in new window

0
 
etech0Author Commented:
Hi!
When I run the batch file, it tells me:

Does C:\Users\me\Desktop\file2.txt specify a file name
or directory name on the target
(F = file, D = directory)?

Can I tell it from within the batch file that it will be a file? I want this to be able to run without user interaction required.
0
 
MikeOM_DBACommented:
You may need to pre-create the directories.
Or do this:
 
XCOPY C:\Folder1\MyFile_%THISDAY%  X:\Folder2\
rem ---- Add a backslash here ---------------^

Open in new window

0
 
etech0Author Commented:
The directory is already there!

Here is my test code:

XCOPY C:\Users\me\Desktop\file.txt C:\Users\me\Desktop\file2.txt

Open in new window

0
 
etech0Author Commented:
Nice!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.