set path="D:\Work,D:\workin,D:\files"
set files ="txt,html,xml"
如何在files
中定义的目录中搜索path
中定义的扩展名的文件,并将其名称写入文件?
以下是我已经尝试过的内容:
set "list=list.txt"
pause
pushd "%~dp0"
>"%list%" (
for /f "delims=" %%i in ('2^>nul dir /ad /b') do (
pushd "%%i"
for /f "delims=" %%j in ('2^>nul dir /a-d /b *.txt *.html') do (
echo %%j& >nul 2>&1 copy/y "%%j" ..
)
popd
)
)
popd
答案 0 :(得分:1)
您应该能够使用标准FOR
命令简化此过程。
@Echo off
>"FileList.log" (
for %%G in (D:\Work,D:\workin,D:\files) do (
pushd "%%~G"
for %%H in (*.xml *.txt *.html) do (
echo %%~H
copy /y "%%~H" ..
)
popd
)
)