Questions

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

+
0 Votes
Locked

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

Dale27
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.
+
1 Votes
robo_dev

@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%

+
0 Votes
Dale27

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

+
0 Votes
Dale27

@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 :-)

+
0 Votes
robo_dev

just work :)