Follow via:
RSS
Email Alert
Question
0 Votes
+ -

How to change filename of file copied in xcopy batch file?

I am currently using a batch file that uses the following code

@ECHO off
XCOPY /y C:\ProCal\Certificates\ProResDB.mdb H:\onsite\Imports\
@ECHO on

to copy one file (ProResDB.mdb) from the folder 'C:\ProCal\Certificates\' to a the folder 'H:\onsite\Imports\'. How can I add the current date and a predefined initial to the filename of the copied file?
Example: ProResDBddmmyyXX.mdb

Alternatively if this can be done in VBScript, feel free to offer suggestions of how to script that.
Updated - 13th Apr 2011

Answers (3)

1 Vote
+ -
For my log files, I use the following code
@echo off

rem get date, make if file name friendly
FOR /F "tokens=1-4 delims=/ " %%i in ('date/t') do set d=%%j-%%k-%%l@%%i@
rem get time, make if file name friendly
FOR /F "tokens=1-9 delims=:. " %%i in ('time/t') do set t=%%i_%%j_%%k%%l

set LOG=%d%%t%.log
ren dump.log %log%
move *.log c:\snort\log\sav

echo YOUR FILE NAME IS : %log%
13th Apr 2011

Replies

Thanks for your reply Robo.

So incorporating that into mine - it kind of does what I need it to do - copy and rename and move. However, the filename I get is: "04-2011-@14@10_33_"

Is there any way to get this to be "ProResDB-dd-mm-yy-hh-mm.mdb"?
Or, without the time and with predefined initials at the end of the filename eg: "ProResDB-dd-mm-yy-ME.mdb"

@ECHO off
XCOPY /y C:\ProCal\Certificates\ProResDB.mdb

rem get date, make if file name friendly
FOR /F "tokens=1-4 delims=/ " %%i in ('date/t') do set d=%%j-%%k-%%l@%%i@
rem get time, make if file name friendly
FOR /F "tokens=1-9 delims=:. " %%i in ('time/t') do set t=%%i_%%j_%%k%%l

set MDB=%d%%t%.mdb
ren ProResDB.mdb %mdb%
move *.mdb H:\Onsite\Imports\

@ECHO on
Dale27 14th Apr 2011
0 Votes
+ -
Got it working...
@ECHO off
XCOPY /y C:\ProCal\Certificates\ProResDB.mdb

rem get date, make if file name friendly
FOR /F "tokens=1-4 delims=/ " %%i in ('date/t') do set d=%%i-%%j-%%k-%%l

set MDB=ProResDB%d%DN.mdb
ren ProResDB.mdb %mdb%
move *.mdb H:\Onsite\Imports\
@ECHO on


Copies the file C:\ProCal\Certificates\ProResDB.mdb, renames the file with the date and initials and moved to H:\onsites\imports\

Thanks for your help Robo happy
14th Apr 2011
0 Votes
+ -
Amazing when things
just work happy
14th Apr 2011
Answer the question
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.