1.

Solve : SET variable substitution problem?

Answer»

Hi,
I'm writing a script to update MS Office path in multiple batch files. My FIRST part finds the files containing the required string...
Code: [Select]setlocal enabledelayedexpansion
if exist ztmplist.txt DEL ztmplist.txt
if exist templist.txt del templist.txt
cd testbatch
rem dir /w *.bat >..\ztmplist.txt
find /I /C "C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE11" *.bat | find /V ": 0" | find "----------" >..\ztmplist.txt
rem pause
for /f "delims=" %%x in (..\ztmplist.txt) do (
    set echLine=%%x
    set echLine=%echLine:~0,-3%
    echo !echLine!>>..\templist.txt
)
Now, ztmplist.txt contains
---------- SCRIPTEXTRACTGLOBAL.BAT: 1

but templist.txt only contains
~0,-3

What I was attempting to do was remove the ": n" (where n could be any number) from the end of the line. Can anyone see where I've gone wrong?

ThanksThink I've got it. Need to change final set to
Code: [Select]set echLine=!echLine:~0,-3!

YES, works now. Also changed so drops PRECEDING hyphens:
Code: [Select]setlocal enabledelayedexpansion
if exist ztmplist.txt del ztmplist.txt
if exist templist.txt del templist.txt
cd testbatch
rem dir /w *.bat >..\ztmplist.txt
find /I /C "C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE11" *.bat | find /V ": 0" | find "----------" >..\ztmplist.txt

for /f "delims=" %%x in (..\ztmplist.txt) do (
   set echLine=%%x
   set echLine=!echLine:~11,-3!
   echo !echLine!>>..\templist.txt
)



Discussion

No Comment Found