Reputation: 31
I'm looking for a little help creating a batch rename script in windows
I have a folder of images, numbered sequentially by 3, ie.
and so on
What i'm aiming to do is copy and rename each one twice so that it makes up the missing images after it, to make up the full image sequence, so that
test_01.001.tif
is copied twice and those copies renamed to:
test_01.002.tif
and test_01.003.tif
And so on for the rest of the image sequence (goes up to 200)
Any help much appreciated, thanks!
Upvotes: 3
Views: 592
Reputation: 529
Another, very tailored, method maybe:
@echo off
setlocal enabledelayedexpansion
set iter=1
set count=1
for %%i in (C:\TEST\*.tif) do (
set name=%%~dpni
pause
if %count%==%iter% (
if !count! lss 10 (
set /a count+=1
copy "%%i" "!name:~0,-1!!count!%%~xi"
set /a count+=1
copy "%%i" "!name:~0,-1!!count!%%~xi"
set /a count+=1
)
if !count! geq 10 if !count! lss 100 (
set /a count+=1
copy "%%i" "!name:~0,-2!!count!%%~xi"
set /a count+=1
copy "%%i" "!name:~0,-2!!count!%%~xi"
set /a count+=1
)
if !count! geq 100 if !count! lss 1000 (
set /a count+=1
copy "%%i" "!name:~0,-3!!count!%%~xi"
set /a count+=1
copy "%%i" "!name:~0,-3!!count!%%~xi"
set /a count+=1
)
) else (
set /a iter+=1
)
)
pause
Change TEST
path to the one relevant to your *.tif
files.
Upvotes: 0
Reputation: 67226
Try this:
@echo off
setlocal EnableDelayedExpansion
for /F "tokens=1-3 delims=." %%a in ('dir /B /A-D *.*.tif') do (
set /A new1=1%%b+1, new2=new1+1
copy "%%a.%%b.%%c" "%%a.!new1:~1!.%%c"
copy "%%a.%%b.%%c" "%%a.!new2:~1!.%%c"
)
Upvotes: 1
Reputation: 80113
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\sourcedir"
SET "basename=test_01."
FOR /l %%a IN (1001,3,1997) DO (
SET /a filename=%%a
IF EXIST "%sourcedir%\%basename%!filename:~-3!.tif" (
SET /a new1=1+%%a
SET /a new2=2+%%a
ECHO(COPY /b "%sourcedir%\%basename%!filename:~-3!.tif" "%sourcedir%\%basename%!new1:~-3!.tif"
ECHO(COPY /b "%sourcedir%\%basename%!filename:~-3!.tif" "%sourcedir%\%basename%!new2:~-3!.tif"
) else GOTO :EOF
)
GOTO :EOF
You would need to change the setting of sourcedir
to suit your circumstances.
The required COPY commands are merely ECHO
ed for testing purposes. After you've verified that the commands are correct, change ECHO(COPY
to COPY
to actually copy the files. Append >nul
to suppress report messages (eg. 1 file copied
)
The process varies %%a
from 1001 to 1997 in steps of 3. If the file with a key namesection of the last 3 digits of %%a is not found then terminate, otherwise add 1 and 2 to %%
giving the two required new files and copy using the same substringing technique.
Upvotes: 0
Reputation: 57272
not tested
@echo off
pushd "C:\the_folder_with_the_images"
setlocal enableDelayedExpansion
for /l %%l in (1 ; 3 ; 201) do (
set current_number=%%l
set next_number=%%l+1
set next_next_number=%%l+2
if %%l lss 100 (
set current_number=0%%l
)
if %%l lss 10 (
set current_number=0%%l
)
if !next_number! lss 100 (
set next_number=0%%l
)
if !next_number! lss 10 (
set next_number=0%%l
)
if !next_next_number! lss 100 (
set next_next_number=0%%l
)
if !next_next_number! lss 10 (
set next_next_number=0%%l
)
copy test_01.!current_number!.tif test_01.!next_number!.tif
copy test_01.!current_number!.tif test_01.!next_next_number!.tif
)
endlocal
Upvotes: 0