xcopy with date

Eljefegeneo

Still trying to learn
Local time
Today, 13:31
Joined
Jan 10, 2011
Messages
902
I have been trying to figure out how to add the date to the new file that is copied with the code:
xcopy /s C:\Users\Gene\Desktop\Folder1\DBMain.accdb C:\Users\Gene\Desktop\Folder2\

I have looked everywhere, copied various codes that said it could be done, but I still can't get it to work.

What I want to to have the new file in Folder2 be DBMaind_DateAndTime
where DateAndTime would be the Date and Time that the copy was made.
 
I finally figured out how to do it from a desktop batch file, you have to add the date and time before the file name. This code works with one exception. It asks if the destination is a file or directory. Does anyone know how to tell it automatically, that is some code that says is is a file and not a directory, or perhaps to have a "f" for file on the prompt? Thanks.

for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY=%year%-%month%-%day%
rem echo %TODAY%
for /f "tokens=1 delims=: " %%h in ('time /T') do set hour=%%h
for /f "tokens=2 delims=: " %%m in ('time /T') do set minutes=%%m
for /f "tokens=3 delims=: " %%a in ('time /T') do set ampm=%%a
set NOW=%hour%-%minutes%-%ampm%
rem echo %NOW%

xcopy /f /q /-y C:\Users\Gene\Desktop\Folder1\DBMain.accdb C:\Users\Gene\Desktop\Folder2\%TODAY%-%NOW%_dbmain.accdb
 

Users who are viewing this thread

Back
Top Bottom