rename extention of a file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Posts: 1
Joined: 11 Jan 2021 04:32

rename extention of a file

#1 Post by ClintonLoomis » 11 Jan 2021 04:37

I have 1000's of files without extensions. but these files are named as below


my request is

search for files containing 12345 in their names and rename them with unique
names of xxxxxxxxxx.txt (10 Char name) with .txt extension.
source and destination folder's are the same E:\test

is this possible

if so please help
thanx in advance

Posts: 1886
Joined: 23 Jun 2013 06:15
Location: Germany

Re: rename extention of a file

#2 Post by penpen » 15 Jan 2021 17:05

You might do something like that (sketched and untested):

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion

set "N=1000000000"
for %%a in ("*12345-*" "*-*12345") do (
	for /f "tokens=* delims=" %b in ('set /a "N"') do (
		echo(ren "%%~a" "%%~b.txt"
	set /a "N+=1"

goto :eof
Sidenote: I echoed the commands it should do, so you can check if that's what you like to perform.
In case you are satisfied with the commands created, you might want to delete the "echo(".


Post Reply