[英]Getting file path within dos batch file within for loop
我正在嘗試創建一個批處理文件,該文件將進入目錄並查找日志文件,然后搜索日志文件以查看單詞“ ERROR:”是否在行首。 我已經弄清楚了那部分。 我現在的問題是嘗試創建一個顯示行,以顯示* .log之后的目錄。
例如
--- c:\\ temp * .log -----------------
--c:\\ temp \\ temp1.log
--c:\\ temp \\ temp2.log
錯誤:溫度錯誤
------- c:\\ temp \\ subdir * .log -----------------
--c:\\ temp \\ subdir \\ temp3.log
錯誤:這是一個錯誤
--c:\\ temp \\ subdir \\ temp4.log
這是我目前正在使用的代碼
Set _OutFile=c:\temp\check_error.txt
If Exist "%_OutFile%" Del "%_OutFile%"
For /F "Tokens=* Delims=" %%I In ('Dir /b "c:\temp\*.log"') Do (
(Echo.
Echo.---------- %%~I
)>>"%_OutFile%"
Findstr /B /C:"ERROR:" "%%I">>"%_OutFile%"
)
這只會產生
---------- TempData.log
它不顯示主路徑或文件路徑。
更改此行:
Echo.---------- %%~I
對此:
Echo.---------- %%~fI
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.