IcemanND, on Apr 2 2005, 06:20 PM, said:
This should work for any text file.
replace "path\textfile" with the path and name of your original file.
replace "originaltext" with the text you want to replace.
replace "newtext" with the text you want instead.
for /f %%L in (path\textfile) DO (
if "%%L"=="originaltext" (
echo newtext>>path\temp.TMP
) ELSE (
echo %%L>>path\temp.TMP
)
)
copy /Y path\temp.TMP path\textfile
<{POST_SNAPBACK}>
I have tried to make a batch file that searches an extracted help file webpage rename it to a text. Then do a find and replace the links in the string. CMD file is called 2 in the attached zip file.
@echo off
Setlocal
set NAME=ntcmds
set FOLDER=cmds
echo Deleting old folder if exists.
IF EXIST %NAME% RD /S /Q %NAME%
Echo Decompiling %NAME% Help file
hh.exe -decompile .\%NAME%\ %WINDIR%\Help\%NAME%.chm
Echo Moving all other files to %FOLDER%
md %NAME%\%FOLDER%
cd %NAME%
move *.* %FOLDER%
Move .\%FOLDER%\%NAME%.htm .\%NAME%.htm
ren %NAME%.htm %NAME%.txt
find "MS-ITS:%NAME%.chm::/" %NAME%.txt /c
The last line of the code is what I want to find and replace. I Then removed it and added see below.
I wanted to change the links in the webpage to see the wepages in the folder below it.
for /f %%L in (%NAME%.txt) DO (
if "%%L"=="MS-ITS:%NAME%.chm::/" (
echo %FOLDER%\>>.\temp.TMP
) ELSE (
echo %%L>>.\temp.TMP
)
)
copy /Y temp.TMP %NAME%.txt
I used the code above to changed the find and replace to be what I want to replace etc.
find = MS-ITS:%NAME%.chm::/
Replace with = %FOLDER%\ or cmds\ but prefer to use the varible
But it doesn't work all that is in the temp file is the first few charaters from each line.
I don't know much about the for command and would like help in understanding it.