Page 1 of 1

Rename File Name based on the contents of the file

Posted: 14 Apr 2009 02:25
by Hangkadim
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.

Posted: 15 Apr 2009 10:03
by avery_larry
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%

Posted: 16 Apr 2009 00:33
by Hangkadim
Thank you sir, its work great.