Solved rename of files by string inside these files

October 11, 2012 at 02:54:44
Specs: Windows XP
Hello all

I need your help to solve this matter of case. which is :

inside folder there are files named lid*.wfcont . inside them there are lines of description like :

#UGC:2 PART 1486 880 800 1 1 15 3100 2012090 000002cb \
#- VERS 0 0 \
#- HOST \
#- LINK \
#- DBID \
#- REVS 0, \
#- RELL 0, \
#- UOBJ_ID 1334218020 1240090252 -1368834949 \
#- MACH SUN_SunOS_5.7_Generic_106541- \
#- CMNM 01dh-740900mkadd26309tbp0002.prt \
#-END_OF_UGC_HEADER

what is important to be able to rename all wfcont files by corresponding name after # CMNM

like in this example - 01dh-740900mkadd26309tbp0002.prt .

of course in each wfcont there is different name and extension ( lenght of that string can be different too but not longer than 35 chars so in rename could be included spaces if possible).

I don't know if it can be done with bat but I appriciate any tip
thanks and regards


See More: rename of files by string inside these files

Report •

#1
October 11, 2012 at 04:18:24
✔ Best Answer
This does one file. You can use nested FOR loops or subroutines to do a bunch.


:: ===== script starts here ===============
::
:: ant.bat 2012-10-11 18:04:23.40
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=1-3 delims= " %%a in (myfile) do (
if "%%b" equ "CMNM" set F=%%c
)
echo ren myfile "!F!"
goto :eof
::====== script ends here =================


====================================
Life is too important to be taken seriously.

M2


Report •

#2
October 11, 2012 at 05:07:41
thanks for quick reply ..
I tested it with

:: ===== script starts here ===============
::
:: ant.bat 2012-10-11 18:04:23.40
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=1-3 delims= " %%a in (lid_5790257404687155202.wfcont) do (
if "%%b" equ "CMNM" set F=%%c
)
ren lid_5790257404687155202.wfcont !F!
goto :eof
::====== script ends here =================
and script renamed this file perfectly ....thanks a lot Mechanix2Go

now just to figure out how to put in a loop for all wfcont files in folder :P

regards


Report •
Related Solutions


Ask Question