Hi,
this is my situation: I'm aving a file (test.pdf) and I want to copy it to another folder and rename it to 120001.pdf. But the goal is also to do this 200 times, so the second time it should become 120002.pdf, the next one 120003.pdf. Is this possible?
jvuz
Copy and rename file
Moderator: DosItHelp
Re: Copy and rename file
'
untested !
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$filename=test"
set "$fileext=pdf"
set "$tdir=C:\this works"
set "$cstart=120001"
set "$cend=120201"
for %%? in (
!$cstart!, 1, !$cend!
) do copy /v /y "!$filename!.!$fileext!" "!$tdir!\!$filename!%%~?.!$fileext!"
endlocal &exit /b 0
Re: Copy and rename file
Thanks a lot Ed. The result is I'm geeting now 3 files:
test1.pdf
test120001.pdf
test120201.pdf
the goal is to get
120001.pdf
120002.pdf
...
120201.pdf
But already thaks a lot.
test1.pdf
test120001.pdf
test120201.pdf
the goal is to get
120001.pdf
120002.pdf
...
120201.pdf
But already thaks a lot.
Re: Copy and rename file
'
oops !
oops !

Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$filename=test"
set "$fileext=pdf"
set "$tdir=C:\this works"
set "$cstart=120001"
set "$cend=120201"
for /l %%? in (
!$cstart!, 1, !$cend!
) do copy /v /y "!$filename!.!$fileext!" "!$tdir!\!$filename!%%~?.!$fileext!"
endlocal &exit /b 0
Re: Copy and rename file
Great! The only thing is it's still showing as test120001.pdf, and so on.
I arranged it by changing the bottom command to this:
for /l %%? in (
!$cstart!, 1, !$cend!
) do copy /v /y "!$filename!.!$fileext!" "!$tdir!\%%~?.!$fileext!"
endlocal &exit /b 0
So the end file is this
I arranged it by changing the bottom command to this:
for /l %%? in (
!$cstart!, 1, !$cend!
) do copy /v /y "!$filename!.!$fileext!" "!$tdir!\%%~?.!$fileext!"
endlocal &exit /b 0
So the end file is this
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$filename=test"
set "$fileext=pdf"
set "$tdir=C:\this works"
set "$cstart=120001"
set "$cend=120201"
for /l %%? in (
!$cstart!, 1, !$cend!
) do copy /v /y "!$filename!.!$fileext!" "!$tdir!\%%~?.!$fileext!"
endlocal &exit /b 0