2013-04-30 30 views
0

我正試圖使用​​Windows中的批處理從文件中刪除多行字符串。我的批處理代碼正在做一些奇怪的事情,比如將字符串ECHO is off.放入文件中。從文件中刪除多行字符串

編輯:所有代碼
我怎樣才能讓我的代碼刪除從文件中多行字符串?多行字符串的

@echo off &setlocal enabledelayedexpansion 

Rem Read file and store all contents in string 
Set replace= 
Set target= 
Set infile=usermenuTest1.4d 
Rem %~1 
Set outfile=usermenuTest2.4d 
Rem %~2 

for /f "delims=" %%i in (%infile%) do set "target=!target! %%i" 
echo %target% 

Rem Remove the target string from myOtherFile.txt: this code is from http://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file 
@echo off & setlocal enabledelayedexpansion 
for /f "tokens=1,* delims=¶" %%A in ('type "%outfile%"') do SET "string=%%A" 
SET "modified=!string:%target%=%replace%!" 
(echo(%modified%)>> "%outfile%" 

例子我想替換:

Menu "User" { 
    Button "" { 
     Walk_Right "" 
    } 
} 

Menu "" { 
    // Button "CAD" { 
    // Walk_Right "CAD"  
    // } 
    Button "Design" { 
     Walk_Right "Design"  
     } 
    Button "Services" { 
     Walk_Right "Services"   
     } 
    Button "Strings" { 
     Walk_Right "Strings"   
     } 
    Button "Survey" { 
     Walk_Right "Survey"   
     } 
    Button "Utilities" { 
      Walk_Right "Utilities"   
     } 
    Button "Zoom" { 
     Walk_Right "Zoom"   
     }   
    } 
+0

後要刪除 – ElektroStudios 2013-04-30 04:29:13

+0

@ElektroHacker請多行示例串編輯例如 – 2013-04-30 04:42:47

回答

0

試試這個:

@echo off & setlocal enabledelayedexpansion 
for /f "tokens=1,* delims=¶" %%A in ('type "%outfile%"') do SET "string=%%A" 
SET "modified=!string:%target%=%replace%!" 
(echo(%modified%)>> "%outfile%" 
+0

sortof工作,'回聲關閉'現在不存在,但我想刪除的字符串仍然存在於文件中,當它不應該。 – 2013-04-30 04:41:13

+0

好的,請顯示%target%和%replace%。 – Endoro 2013-04-30 04:54:17

+0

我使用顯示所有變量的完整代碼編輯了我的問題 – 2013-04-30 05:03:51