如何遍历目录树并对其中的每个文件运行命令?

如何遍历目录树并对其中的每个文件运行命令?

cmd.exe粗略地看一下输出后使用help for

命令:FOR /R \Music %file IN (*.flac *.wav *.aif) DO C:flac.exe -f -8 %file
响应:%file was unexpected at this time.

命令:FOR /R \Music %file% IN (*.flac *.wav *.aif) DO C:flac.exe -f -8 %file%
响应:%file% was unexpected at this time.

答案1

这对我有用:

代替:

"c:\Full_Path_to\Music"完整路径到您的\Music文件夹

@C:\Where\FLAC\Are\flac.exe完整路径Flac.exe

for %i in (flac wav aif)do for /f %F in ('where /r "c:\Full_Path_to\Music" "*.%i"')do C:\Where\FLAC\Are\flac.exe -f -8 "%F"

或者,对于 bat 文件:

@for %%i in (flac wav aif)do @for /f %%F in ('where /r "c:\Full_Path_to\Music" "*.%%i"')do @C:\Where\FLAC\Are\flac.exe -f -8 "%%F"

另外,你可以尝试这个:

cd /d "C:\Full_Path_to\Music" && for /r %%i in (*.flac,*.wav,*.aif)do @"C:\Where\FLAC\Are\flac.exe" -f -8 "%%~i"

相关内容