Page 1 of 1
Re-Number files
Posted: 22 Feb 2016 12:49
by jeff p
Renumber files?
I have 12,000 images in Z:\Images\Renders that i'd like to re-unumber. its a mix of .jpg's, and tga's.
My current folder looks like this:
IMG_00000.tga
IMG_00001.jpg
IMG_00002.jpg
IMG_00003.jpg
IMG_00004.jpg
IMG_00004.tga
IMG_00005.jpg
IMG_00006.jpg
IMG_00006.tga
etc..
I'd like to strip any information but the incremental number, to look like this:
00001.tga
00002.jpg
00003.jpg
00004.jpg
00005.jpg
00006.tga
00007.jpg
00008.jpg
00009.tga
Is this possible?
Thanks for any help!
Re: Re-Number files
Posted: 22 Feb 2016 14:08
by foxidrive
It's easy, but the actual filename format needs to be known because it changes the code.
Are the filenames exactly as you show there?
Re: Re-Number files
Posted: 22 Feb 2016 14:50
by aGerman
Assuming that always the last 5 characters of the file name are the incremental number you may try that code:
Code: Select all
@echo off &setlocal
set "nonum="
for /f "delims=" %%i in ('dir /a-d /b *.tga *.jpg') do (
set "file=%%i"
set "name=%%~ni"
setlocal EnableDelayedExpansion
for /f "delims=1234567890" %%j in ("!name:~-5!") do set "nonum=%%j"
if not defined nonum ren "!file!" "!name:~-5!%%~xi"
endlocal
)
Regards
aGerman
Re: Re-Number files
Posted: 22 Feb 2016 23:46
by jeff p
Thanks for the replies!
Foxdrive, Yes the file name will always remain the same for each set of images to renumber.... In this case it's IMG_ in another set it might be IMGR_ ( if there's a way for me to modify the code such that I can account for an additional character space for a different name, thats easy for me.)
aGerman, I tried your code but was unable to get it to work. (using a set of 100 images from IMG_00000.tga to IMG_00100.jpg I placed the bat file in the same directory as the images...but no luck)
Any ideas?
Thanks for the help!
Re: Re-Number files
Posted: 23 Feb 2016 03:25
by foxidrive
Launch this and open "Z:\Images\Renders\temp.bat.txt" to check the commands.
If it's ok then rename and launch that temporary batch file.
Code: Select all
@echo off
pushd "Z:\Images\Renders\"
(for %%a in (*.tga *.jpg) do (
for /f "tokens=1,* delims=_" %%b in ("%%a") do echo ren "%%a" "%%c"
))>"temp.bat.txt"
echo check "Z:\Images\Renders\temp.bat.txt" and rename and run.
pause
Re: Re-Number files
Posted: 23 Feb 2016 13:08
by jeff p
Thanks, foxidrive.
Your code removed the first name prefix. ( IMG_) and left the number sequence unchanged. .. However the temp.bat.txt file it created gave me the idea to simply follow that line of reasoning and rename all these manually in the same fashion.
Thanks again for the help.
Cheers
Jeff
Re: Re-Number files
Posted: 28 Feb 2016 05:40
by [newbie]
Hi,
here a small oneliner, pase the code in
cmd box where the jpg/tga located
Code: Select all
cmd /v:on /c "for /f %i in ('dir /b /a-d "*.jpg" "*.tga"') do @(set "file=%~ni" &set "file=!file:~-4!" &echo ren %i !file!%~xi)"
remove the
echo to finally rename
not needed a
batch file