我撰寫了一個簡單的批處理檔案來搜索特定的字串。
forfiles /S /M TraceLog-* /d %SearchDate% /c "cmd /c findstr /c:\"Not enough disk space to save focus debug data.\" @path" >> %FileName%
有沒有辦法停止運行,所以輸出檔案將只包含一條訊息“沒有足夠的磁盤空間來保存焦點除錯資料”。這意味著 - 如果找到上述字串 - 停止回圈。
uj5u.com熱心網友回復:
該forfiles命令不提供在滿足某個條件后終止回圈的功能。
但是,您可以改為讓回圈完成,但將其輸出寫入臨時檔案,然后將其第一行復制到目標日志檔案中:
rem // Do the loop but write output into a temporary file:
forfiles /S /M "TraceLog-*" /D %SearchDate% /C "cmd /D /C findstr /C:\"Not enough disk space to save focus debug data.\" @path" > "%FileName%.tmp"
rem // Read the first line from the temporary file and store it in variable `LINE`:
< "%FileName%.tmp" (set "LINE=" & set /P LINE="")
rem // Append the read first line to the target log file:
if defined LINE echo(%LINE%>> "%FileName%"
rem // Eventually clean up the temporary file:
del "%FileName%.tmp"
此代碼(錯誤)使用set /P旨在提示用戶讀取檔案的第一行并結合輸入重定向<的值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/533263.html
標籤:批处理文件查找字符串文件
