Rename File Name based on the contents of the file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Hangkadim
Posts: 2
Joined: 14 Apr 2009 01:21

Rename File Name based on the contents of the file

#1 Post by Hangkadim » 14 Apr 2009 02:25

Hi All,
Been looking around still unable to figure out how to do this.
How do I rename a file based on the contents of the file, Example File1.txt contains this value 'ABC123,07072006,BCA,128-99' the file need to be rename based on the first 6 characters of the value ie ABC123.txt.

Thanks in advance.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 15 Apr 2009 10:03

Something like this (untested):

Code: Select all

for /f %%a in (file.txt) do (
   set fname=%%a
   goto :process
)

:process
ren file.txt %fname:~0,6%

Hangkadim
Posts: 2
Joined: 14 Apr 2009 01:21

#3 Post by Hangkadim » 16 Apr 2009 00:33

Thank you sir, its work great.

Post Reply