Question

Locked

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

By 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.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

For my log files, I use the following code

by robo_dev In reply to How to change filename of ...

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

Collapse -

Reponse To Answer

by Dale27 In reply to For my log files, I use t ...

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

Collapse -

Got it working...

by Dale27 In reply to How to change filename of ...

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

Collapse -

Amazing when things

by robo_dev In reply to How to change filename of ...

just work :)

Back to Software Forum
5 total posts (Page 1 of 1)  

Software Forums