Computing.Net > Forums > Programming > Auto renaming

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.

Auto renaming

Reply to Message Icon

Name: TerryE
Date: July 16, 2009 at 11:38:10 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

I’m tiring to get a .bat file to rename oeminfo.ini to oeminfoBAK.ini and if it exist to auto rename oeminfoBAK1.ini and so on.
if exist c:\windows\system32\oeminfoBAK.ini ren c:\windows\system32\oeminfo.ini oeminfoBAK2.ini and
if exist c:\windows\system32\oeminfo.ini ren c:\windows\system32\oeminfo.ini oeminfoBAK.ini works but I know there is a better way.
I’m not to good at this and it looks like you all have it mastered, your help would be deeply appreciated.

Thanks,
Terry



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: July 20, 2009 at 16:55:56 Pacific
Reply:

Hi Terry
Try This

@echo off
SetLocal EnableDelayedExpansion

set FPath=c:\windows\system32\oeminfo
set Num=0

if exist %FPath%.ini (ren %FPath%.ini oeminfoBAK.ini & exit/b)
dir /b %FPath%BAK*.ini | find "oeminfoBAK" > Files.txt

for /f "tokens=1-2 delims=BAK" %%a in (Files.txt) do (
for /f "tokens=1 delims=.ini" %%c in ("%%b") do (set Num=%%c)
if !Num! EQU 0 (ren !FPath!BAK.ini oeminfoBAK1.ini)
if !Num! GTR 0 (
set /a Num2=!Num!+1
ren !FPath!BAK!Num!.ini oeminfoBAK!Num2!.ini
)
)
del Files.txt


0
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: Auto renaming

Please Help renaming files www.computing.net/answers/programming/please-help-renaming-files/19700.html

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

auto date stamping a files www.computing.net/answers/programming/auto-date-stamping-a-files/19502.html