How to batch copy and rename with date

January 3, 2011 at 01:15:32
Specs: Windows XP
With help from another post on this site, I have created a batch file that copies a file from one system to another. The file is renamed and the date that it is copied is added to the new name. Here is an example of one of my batch files:

echo off
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XYear=%%c
echo Date=%XDate% Year=%XYear%
echo on
copy "\\\Files\assets\Science\scienceinaction.mp3" "\\server\dropbox\BBC_Science In Action %XDate%_%XYear%_51613.mp3"

What I would really like to be able to do is to get the XDate variable from the date of the original/first file, rather than the system date when it is copied. Is there any way to do this? I am using WinXP.

See More: How to batch copy and rename with date

Report •

January 3, 2011 at 02:55:03
Post the output of this bat:

@echo off > #& setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b #') do (

Life is too important to be taken seriously.


Report •

January 3, 2011 at 04:31:56
Thanks for the help. Since posting, I have done what I should have done in the first place - Googled! With some more help from this site and others, I have written a new batch file that does what I need and adds logging too. i am posting it here hoping it will help others.

echo off
rem Source & destination settings
set iPumpfile=\\\Files\assets\Science\scienceinaction.mp3
set DADArtist=BBC
set DADTitle=Science In Action
set DADCut=51613
IF NOT EXIST %iPumpfile% goto LOGTEXT
rem Get date of file from iPump
for %%a in (%iPumpfile%) do set FileDate=%%~ta
rem Stip off time
set FileDate=%FileDate:~0,10%
rem Change delimiters from / to -
for /f "tokens=1-3 delims=/- " %%a in ("%FileDate%") do set FileDate=%%a-%%b-%%c
rem get current system year
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XYear=%%c
rem Display and send to Dropbox
echo Copied %iPumpfile% to "\\server\dropbox\%DADArtist%_%DADTitle% %FileDate%_%XYear%_%DADCut%.mp3" on %DATE% at %TIME% >>log.txt
copy %iPumpfile% "\\server\dropbox\%DADArtist%_%DADTitle% %FileDate%_%XYear%_%DADCut%.mp3"
goto END
echo %iPumpfile% not found on %DATE% at %TIME% >>log.txt

Report •

Related Solutions

Ask Question