renaming .log files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
joe
Posts: 35
Joined: 06 Sep 2017 07:56

renaming .log files

#1 Post by joe » 12 Dec 2017 07:40

hi

this one is tricky and hope all the genius out there can help me out of this mess.

I have 1000's of .log files in a folder which are to be renamed sequentially.

but the conditions are.

1. The script should read from a .txt (anyname.txt) file which would contain the starting number sequence ie.. (if the anyname.txt file would contain 00213 or any 5 digit number)

2. The batch file should start renaming from 00214.log..00215.log..00216.log and so on till the end of file count in the folder.

3. After renaming all the files sequentially in the folder the batch script should update the anyname.txt file with the last number of file count to continue on the next run.

I have searched the for this type of batch script but in vain.

pl help me out of this mess

thanx to those who r going to help me out in advance..

joe

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: renaming .log files

#2 Post by aGerman » 12 Dec 2017 08:14

If the already renamed files are still in the same folder it would have been easy to determine the last number without additional text file. Nevermind.

I assume you want to exclude files where the file names already consist of 5 digits.

Code: Select all

@echo off &setlocal
set "numfile=a.txt"

set /p "n="<"%numfile%"
set /a "n=1%n%"

for /f "delims=" %%i in ('dir /a-d /b "*.log"^|findstr /vix "[0-9][0-9][0-9][0-9][0-9]\.log"') do (
  set /a "n+=1"
  set "f=%%~i"
  setlocal EnableDelayedExpansion
  ren "!f!" "!n:~-5!.log"
  endlocal
)

>"%numfile%" echo %n:~-5%
Steffen

joe
Posts: 35
Joined: 06 Sep 2017 07:56

Re: renaming .log files

#3 Post by joe » 12 Dec 2017 08:54

steffen


Oh my god I just cant believe it you have pulled me out of the mess wowwwwww . great

Thank you man so grateful..
8) 8) 8)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: renaming .log files

#4 Post by aGerman » 12 Dec 2017 09:17

Welcome joe.

Post Reply