file / extension renaming

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

file / extension renaming

#1 Post by joe » 26 Nov 2017 09:54

hi

I have hundreds of log files in a directory named (any name).12345 (the extension is of five digits).
my request is to rename all files in that folder with a unique name and .txt extension.

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

Re: file / extension renaming

#2 Post by aGerman » 26 Nov 2017 10:04

How should your unique names look like? And is there any rule where to start (e.g. by file name ascending or by file time)?
Another possibility could be to just append .txt to the files. They would look like "whatevername.12345.txt" afterwards.

Steffen

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

Re: file / extension renaming

#3 Post by joe » 26 Nov 2017 19:20

yes just append a .txt to file because its already names with ddmmyyhhmmss format

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

Re: file / extension renaming

#4 Post by aGerman » 27 Nov 2017 01:57

Code: Select all

for /f "delims=" %%i in ('dir /a-d /b *.* ^| findstr /e "\.[0-9][0-9][0-9][0-9][0-9]"') do (
  ren "%%~i" "%%~i.txt"
  REM ren "%%~i" "%%~ni.txt"
)
The commented line would replace the extension .12345 with .txt while the first line appends .txt to the original file name.

Steffen

Post Reply