使用xcopy查找和复制文件

时间:2015-10-21 11:16:00

标签: batch-file xcopy

xcopy支持*通配符,甚至允许您克隆整个目录结构。我的项目使用了我需要分发的这些Qt库:

Qt5CLucene.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Help.dll
Qt5Multimedia.dll
Qt5Network.dll
Qt5PrintSupport.dll
Qt5Sql.dll
Qt5Svg.dll
Qt5Widgets.dll
Qt5Xml.dll
Qt5XmlPatterns.dll

它们并非全部位于Qt安装的同一目录中,并且列表可能会发生变化 - 尤其是添加内容。所以我想使用通配符/*/在目录树中的任何位置查找文件:

C:\Qt\5.3.0-64> xcopy ".\*\%NAME%.dll" "%~dp0\release"

它无法正常工作,找不到文件。这是完整的代码:

C:
cd C:\Qt\5.3.0-64\ 

For %%a in (
  "Qt5CLucene"
  "Qt5Core"
  "Qt5Gui"
  "Qt5Help"
  "Qt5Multimedia"
  "Qt5Network"
  "Qt5PrintSupport"
  "Qt5Sql"
  "Qt5Svg"
  "Qt5Widgets"
  "Qt5Xml"
  "Qt5XmlPatterns"
  ) do (
xcopy ".\**\%%~ad.dll" "%~dp0\debug"
)

那么我可以以某种方式避免在批处理中篡改完整路径(例如。qtbase\bin\Qt5CLucene)吗?

2 个答案:

答案 0 :(得分:1)

尝试这样(xcopy可以询问您是否要创建目录 - 而是使用副本):

For /r "C:\Qt\5.3.0-64\" %%a in (
  "*Qt5CLucene.dll"
  "*Qt5Core.dll"
  "*Qt5Gui.dll"
  "*Qt5Help.dll"
  "*Qt5Multimedia.dll"
  "*Qt5Network.dll"
  "*Qt5PrintSupport.dll"
  "*Qt5Sql.dll"
  "*Qt5Svg.dll"
  "*Qt5Widgets.dll"
  "*Qt5Xml.dll"
  "*Qt5XmlPatterns.dll"
) do (
   copy /y "%~fa" "%~dp0\debug"
)

答案 1 :(得分:0)

如果我理解正确,您希望将所有* .dll文件从C:\ Qt \ 5.3.0-64 \ -folder及其子文件夹复制到脚本文件文件夹的调试子文件夹中。

您可以尝试这样的事情:

:: Start of your *.bat or *.cmd file
FOR /R C:\Qt\5.3.0-64\ %%a IN (*.dll) DO (
   xcopy "%%~a" "%dp~0debug\"
)
:: End of your *.bat or *.cmd file
相关问题