Rename text file based on content

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Serpent
Posts: 12
Joined: 08 Sep 2013 17:18

Re: Rename text file based on content

#31 Post by Serpent » 10 Sep 2013 04:52

hey i send you a PM

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Rename text file based on content

#32 Post by foxidrive » 10 Sep 2013 05:33

I had a look at a few files. Some have illegal filename characters in the first section so they will fail to rename.

Some will have trailing spaces, as the format is not consistent, but try this.



Code: Select all

@echo off
for /f "delims=" %%a in ('dir *.txt /b /a-d ') do call :next "%%a"
pause
goto :EOF
:next
set /p "var="<"%~1"
for /f "delims=/," %%b in ("%var%") do ren "%~1" "%%b%~x1"

Post Reply