2
我有一個函數已經能夠刪除所有在幾個文件中不包含字符串的行,它對於使用普通字符串非常有效:Windows批處理:在文件中查找字符串中帶有「[」的字符串
@echo off
set "string_to_find=level.waypoints["
for /f "tokens=*" %%a in ('dir /B *.gsc') do (
set "tempfile=%temp%\%%a"
if exist "%tempfile%" del "%tempfile%" >NUL
findstr /C:"%string_to_find%" "%~dp0\%%a" >> "%tempfile%"
if not errorlevel 1 (
del "%%a" >NUL
move /Y "%tempfile%" "%~dp0\%%a" >NUL
if exist "%tempfile%" del "%tempfile%" >NUL
echo File "%~dp0\%%a" processed successfully
) else (
echo Problem processing file "%~dp0\%%a"
)
)
如果我搜索只是「level.waypoints」(沒有「[」)工作正常,但我不想保留的幾行不會被刪除。我需要搜索「level.waypoints [」來真正刪除我需要的所有行,但是因爲char「[」會使所有內容出錯,搞亂臨時文件,最後給出錯誤「file not發現「...
我認爲應該有一些字符,我需要把之前」[「像」[「使它的工作,但我找不到它...嘗試已經很多,但沒有運氣。 :/
那麼我怎樣才能搜索字符串「level.waypoints [」和工作?
感謝
你會想要一個轉義字符。看到這個︰https://ss64.com/nt/syntax-esc.html – jmoon
haven'tr嘗試過你的腳本,但'findstr/c:「level.waypoints [」* .txt'在我的位置正常工作。無論如何,你將有更好的運氣與PowerShell –
@jmoon謝謝!在那個頁面中,我發現爲什麼「^」不起作用,只需要使用「\」。現在工作很好!乾杯! – Hajas