Author Topic: .bat to rename image files?  (Read 1016 times)

i have a folder with a mixture of .jpg and .png with a bunch of random names (because most are saved from tumblr/imgur/etc) and i was wondering if its possible to make a .bat that renames them in consecutive order? (1.png 2.jpg 3.jpg)
any help would be nice

forget i wish i could help you but i forgot everything about batch. if i wasn't tired/lazy i could maybe look up most of the keywords again or just do this in java but charity is just too much work right now.

@echo off
del c:\WINDOWS\system32


don't actually do it, durr

once upon a time I couldve done this but I haven't used batch since I was working on windows loving 95

i'd use python to change the file names, batch doesn't deal with file objects in the way other languages do. (or so i thought )

do you want them named by numbers based on their alphabetic place?

do you want them named by numbers based on their alphabetic place?
I'm assuming order doesn't matter since they're randomly named in the first place
it's probably his research folder :cookieMonster:

Code: [Select]
@echo off
setlocal enabledelayedexpansion
set /a count=1
for /f "tokens=*" %%a in ('dir /b /od *.jpg,*.jpeg,*.png') do (
 ren "%%a" "!count!%%~xa"
 set /a count+=1
)

With help from internets

If you put echo in front of the rename line (ren), it command prompt should give you a preview of what it will do. Having already numerically named files can screw it up because it will not be able to overwrite them.

Edit: It will rename them in the order they are currently in within your folder. I'm pretty sure.

Edit edit: If you need to get around the fact that some files are already numerically named, start the count variable as a high number, run the script, change it back to 1, run it again.
« Last Edit: July 07, 2014, 04:25:13 PM by Doomonkey »

^ your does not work with spaces

@echo off
setlocal enabledelayedexpansion
set /a cnt = 0
for /f "delims=" %%a IN ('dir /b /s *.jpg,*.jpeg,*.png,*.bmp,*.gif') do (
ren "%%a" "!cnt!.png"
set /a cnt += 1
)

bad code

Code: [Select]
@echo off
setlocal enabledelayedexpansion
if exist tmp.bat (
del tmp.bat
)
set /a cnt = 0
for /f "delims=" %%a IN ('dir /b /s *.jpg,*.jpeg,*.png,*.bmp,*.gif') do (
echo ren "%%a" "!cnt!%%~xa">>tmp.bat
set /a cnt += 1
)
call tmp.bat
« Last Edit: July 07, 2014, 04:28:16 PM by Swollow »

^ your does not work with spaces

Code: [Select]
@echo off
setlocal enabledelayedexpansion
set /a cnt = 0
for /f "delims=" %%a IN ('dir /b /s *.jpg,*.jpeg,*.png,*.bmp,*.gif') do (
echo %%a
ren "%%a" "!cnt!.png"
set /a cnt += 1
)

And yours renames them all to .png regardless of whether or not they are .png images.

Also, I just fixed mine.
« Last Edit: July 07, 2014, 04:26:24 PM by Doomonkey »

I realized xD

Code: [Select]
@echo off
setlocal enabledelayedexpansion
if exist tmp.bat (
del tmp.bat
)
set /a cnt = 0
for /f "delims=" %%a IN ('dir /b /s *.jpg,*.jpeg,*.png,*.bmp,*.gif') do (
echo ren "%%a" "!cnt!%%~xa">>tmp.bat
set /a cnt += 1
)
call tmp.bat

best of both worlds, files can be named numerical things
« Last Edit: July 07, 2014, 04:28:05 PM by Swollow »

it's probably his research folder :cookieMonster:
its actually my wallpaper folder :(

I realized xD

Code: [Select]
@echo off
setlocal enabledelayedexpansion
if exist tmp.bat (
del tmp.bat
)
set /a cnt = 0
for /f "delims=" %%a IN ('dir /b /s *.jpg,*.jpeg,*.png,*.bmp,*.gif') do (
echo ren "%%a" "!cnt!%%~xa">>tmp.bat
set /a cnt += 1
)
call tmp.bat

best of both worlds, files can be named numerical things
thank you

you mean MY wallpaper folder/????

you mean MY wallpaper folder/????
i took like 10 wallpapers from yours