# Creating Batch file with copy command



## milindsaraswala (May 28, 2008)

I am looking for some batch file to create that copy file to another directory but I want to copy the files with concatenate original file with system time without changing its extension. For example I want to copy file from C:\Temp to D:\Temp and 
C:\Temp have 
a.txt
b.txt
c.txt
suppose when I run batch file at 28-may-2008 9.00 am and start copy to D:\Temp it should rename file like this
a25-05-2008_9-00.txt
b25-05-2008_9-00.txt
c25-05-2008_9-00.txt


----------



## TheOutcaste (Aug 8, 2007)

This will do it. You may have to adjust the variables to match your regional settings, this is set for US, where today would be displayed as Wed 05/28/2008
To see how your system displays the date and time, open a command prompt and type
*Echo.%date%*
and
*Echo.%time%*
Time is 24 hour format. Easy to modify the hour in the batch file to 12 hour format if needed.
You can use multiple lines like the blue ones to specify individual files, or use the red lines to copy all files in the specified source folder


```
@echo off
for /f "tokens=1-4 delims=/ " %%I in ("%date%") do Set _Day=%%I& Set _Month=%%J& Set _Date=%%K& Set _Year=%%L
for /f "tokens=1-2 delims=:" %%I in ("%time%") do Set _Hour=%%I& Set _Minute=%%J
::Specify each file name
[COLOR=Blue]Copy C:\temp\a.txt D:\Temp\a_%_Date%-%_Month%-%_Year%_%_Hour%-%_Minute%.txt
Copy C:\temp\b.txt D:\Temp\b_%_Date%-%_Month%-%_Year%_%_Hour%-%_Minute%.txt[/COLOR]
::Or use this to copy every file
[COLOR=Red]Set _source=C:\Temp
Set _dest=D:\Temp
For /F "tokens=*" %%I In ('dir /b /a-d "C:\Temp"') do Copy %_source%\%%~nxI %_dest%\%%~nI_%_Date%-%_Month%-%_Year%_%_Hour%-%_Minute%.%%~xI[/COLOR]
for %%I in (Day Month Date Year Hour Minute source dest) Do set _%%I=
```
I also added an underscore after the file name so it will be renamed like this:
a_25-05-2008_9-00.txt

Jerry


----------



## milindsaraswala (May 28, 2008)

Thanx for a reply


----------

