我想開始將檔案夾中的數百個環繞媒體檔案混合為立體聲,但這是一個需要很多時間的程序。我想創建一個批處理檔案,ffmpeg該檔案對這組檔案(可能在 .txt 中列出dir /s /b)執行我的命令,我可以在我的 PC 開啟時運行,但還保留已處理檔案的記錄以排除在下一次運行。
我知道我可以通過簡單地向回圈中添加類似的內容來輕松跟蹤已處理的檔案if errorlevel 0 echo "%%~fg">>processed.txt,但是我發現想出一種在下次運行腳本時忽略這些檔案的方法具有挑戰性。
當然,我總是可以手動編輯要回圈的檔案串列并洗掉已處理的檔案串列,但我想知道是否有一種聰明的方法可以以編程方式進行
uj5u.com熱心網友回復:
將日志與 findstr 一起使用的示例。將定義替換為Set "SourceList=%~dp0list.txt"用于存盤要處理的檔案串列的檔案的檔案路徑,或修改 for /f 回圈選項以迭代Dir命令的輸出。
@Echo off
If not exist "%TEMP%\%~n0.log" break >"%TEMP%\%~n0.log"
Set "SourceList=%~dp0list.txt"
For /f "usebackq delims=" %%G in ("%sourceList%")Do (
%SystemRoot%\System32\Findstr.exe /xlc:"%%G" "%TEMP%\%~n0.log" >nul && (
Rem item already processed and appended to log. do nothing.
) || (
Rem item does not exist in log. Proccess and append to log.
Echo(Proccess %%G
>>"%TEMP%\%~n0.log" Echo(%%G
)
)
uj5u.com熱心網友回復:
我設法產生了一種不依賴外部工具并且僅使用for回圈執行作業的方法。由于需要使用 UTF-8,因此在批處理檔案結束后采取了額外的步驟來正確恢復代碼頁:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "tokens=*" %%G in ('%SystemRoot%\System32\chcp.com') do for %%H in (%%G) do set /A "CodePage=%%H" 2>nul
%SystemRoot%\System32\chcp.com 65001 >nul 2>&1
if not exist "%~dpn0.log" break >"%~dpn0.log"
set "FileList=%~dp0FileList.txt"
set "LogFile=%~dpn0.log"
for /f "usebackq delims=" %%G in ("%FileList%") do (
set "SkipFile="
for /f "usebackq delims=" %%H in ("%LogFile%") do (
if "%%G" == "%%H" (
set "SkipFile=1"
)
)
if not defined SkipFile (
echo --^> Processing file "%%~nG"
rem file is processed
) else (
echo "%%~nG" has already been processed
rem file is not processed
)
)
%SystemRoot%\System32\chcp.com %CodePage% >nul
endlocal
可以看出,這個答案的一部分是受到@ T3RROR的啟發!
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/427745.html
上一篇:創建遍歷兩個串列的新串列
