Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
First off could someone help me by explaining some of the basics of renaming in a batch file. Such as how to rename all files in a folder to something_# with # being a growing number. I don't understand the variables and other parts used to do this.
Also how could you rename the files in a folder to the folder name plus a number and be able to skip files that are already named that way and continue with the next "unused" name. Such as folder_001.jpg exists and the next file will be named folder_002.jpg so the first file is left unchanged.
I ask this since i get new files to add to the folder and wish to leave the older ones named the same.

@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir/b/a-d *.jpg') do (
set /a N+=1
echo %%a | find "_" > nul
if errorlevel 1 ren %%a %%~Na_!N!.jpg
)
=====================================
If at first you don't succeed, you're about average.M2

I tried that and played with it a bit and it didn't do exactly what I'd like.
I believe to get what I want the script would have to check if there are properly named files first then rename improperly named files.
I have folders that have files in them like this
\foldera
foldera_001.ext
foldera_002.ext
foldera_003.extThen over time I add new randomly named files such as
874855947347.ext
234534565476.ext
234690844890.extI'd like the first files to remain unchanged while renaming the random files to
foldera_004.ext
foldera_005.ext
foldera_006.extWould it be to complicated to make a batch file that can do that. Or has anyone ever heard of a program that will rename like this easily, since I've never found one.

It could get pretty hairy in a batch file. Not least because numbers with leading zeros are seen as octal.
I use a picture viewer/adjuster called ThumbsPlus [shareware] which does just what you want.
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |