Thursday 14 Jul, 2011 - 07:10am |
2 comments |
I have found a recent blog very helpful but I
can't get it to work in my revised application.
The following is suppose to add a job number to
the front of .xls files with different names.
Neither options work but I can: copy /-Y
"Y:folder(Grating) *.xls"
.\%jobnumber%_(Grating).xls
but this would obviously copy multiple files to
overwrite the same filename.
The error is that the path or file is not found.
Can anyone tell me what is wrong please?
@ echo off
set /p jobnumber=What is the job number?
if "%jobnumber%"=="" goto 0
echo To copy one of the following to the current
folder:
echo 1. Grating 1
echo 2. Grating 2
echo Any other key - Quit
set /p userinp=Choose a number:
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
goto 0
:1
for %%a in ("Serverfolder1folder2(Grating)*.xls")
do copy "%%a" ".\%jobnumber%_%%a"
goto 0
:2
for %%a in ("Y:folder(Grating)*.xls") do copy
"%%a" ".\%jobnumber%_%%a"
goto 0
:0
pause
For anyone else that wants to know, the %%a includes the drive so originally %%a was "Y:etc." so when I added jobnumber to the front it was "5555_Y:etc."
The following includes %%~na to change it to filename only and %%~xa to add the extension back.
for %%a in ("Y:folder(Grating)*.xls") do copy "%%a" ".\%jobnumber%_%%~na%%~xa"
Hope it helps