我有一个名为
Private
的文件夹,其中包含许多子文件夹。每个文件夹都包含许多 zip 文件。
现在我想创建一个批处理文件,将包含字母
Win
的所有子文件夹中的所有 zip 复制到另一个文件夹。源路径是 F:\_QA\Private\
,目的地是 F:\_QA\Zips\
。
我最初只是尝试使用
复制所有zip进行测试XCOPY F:\_QA\Private\ F:\_QA\Zips\
这似乎不起作用。
您将需要使用
dir
命令,该命令可以递归输出所有 zip 文件,然后过滤输出并复制结果。这是一个经过测试的脚本,可以做到这一点:
@echo off
set "fromPath=F:\_QA\Private"
set "destinationPath=F:\_QA\Zips"
if not exist "%destinationPath%" mkdir "%destinationPath%"
:: The findstr is to filter a case-sensitive "Win", as the dir command
:: is always case-insensitive. Feel free to remove that part.
for /f "usebackq delims=" %%A in (`dir "%fromPath%\*Win*.zip" /b /s ^| findstr /c:"Win"`) do (
echo Copying "%%A"...
copy /y "%%A" "%destinationPath%" > NUL
)
echo.
echo Complete!
pause
请注意,我使用
^| findstr /c:"Win"
来确保路径包含带有大写字母 Win
的 W
,因为 *Win*.zip
不区分大小写。