2015-08-09 53 views
6

tests.txt中每個文本的最後一個單詞是「</a>」,我輸入了這個單詞並且它似乎沒有問題,但當我echofor循環中,cmd給了我這個錯誤:「系統找不到指定的文件。」
我知道問題出在「<」和「>」符號上,它代表重定向,這就是錯誤的產生方式。我如何讓cmd認爲我正在使用字符串而不是重定向?BATCH - 使用字符串(< , >)而不是重定向

@echo off 
setlocal EnableDelayedExpansion 

set "remove_char=< /a>" 
echo !remove_char! 

for /f "skip=2 tokens=6*" %%a in (testing.txt) do (
    set "string=%%a %%b" 
    set string=!string:%remove_char%=! 
    echo !string! 

) 

pause >nul 
+1

[如何將重定向符號(< and >)傳遞給Windows批處理文件函數?](http://stackoverflow.com/questions/21406151/how-to-pass-redirect-symbols-and-to- a-windows-batch-file-function) –

+3

嘗試使用'set「string =!string:%remove_char%=!」' – npocmaka

回答

0

也許你可以用

for %%i in (!remove_char!) do (set string=!string:%%i=!) 
1

替換該行

set string=!string:%remove_char%=! 

如果你想使用<和>符號作爲變量,你必須改變他們^ <或^>

否則它們將被視爲輸入或輸出!

相關問題