Computing.Net > Forums > Programming > Batch file Renaming Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file Renaming Help

Reply to Message Icon

Name: pball
Date: October 8, 2007 at 14:19:37 Pacific
OS: XP Pro
CPU/Ram: 1 gig
Product: homemade
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: October 9, 2007 at 01:58:28 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /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



0

Response Number 2
Name: pball
Date: October 9, 2007 at 12:47:38 Pacific
Reply:

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.ext

Then over time I add new randomly named files such as
874855947347.ext
234534565476.ext
234690844890.ext

I'd like the first files to remain unchanged while renaming the random files to
foldera_004.ext
foldera_005.ext
foldera_006.ext

Would 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.


0

Response Number 3
Name: Mechanix2Go
Date: October 9, 2007 at 13:54:17 Pacific
Reply:

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



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file Renaming Help

Batch file renaming www.computing.net/answers/programming/batch-file-renaming/18676.html

Simple Batch File command help www.computing.net/answers/programming/simple-batch-file-command-help/16568.html

Automated batch-file renaming www.computing.net/answers/programming/automated-batchfile-renaming/13367.html