仅复制将另一个文件作为同级的文件[基于扩展]?

发布于 2025-01-23 01:02:06 字数 981 浏览 3 评论 0原文

我正在尝试使用ANT将C ++构建的一些文件复制到另一个目录中。

构建的输出看起来像这样:

/Build
   /LibA
      LibA.lib
      LibA.pdb
   /LibB
      LibB.lib
      LibB.pdb
   /ProjA
      myexe.exe
      myexe.pdb
   /Foo
      foo.exe
      foo.pdb
   /...

现在,我想复制所有*。EXE文件及其*。pdb文件(但不是*。pdb libs的文件)​​。

我尝试了:

<copy todir="outdir">
   <fileset dir="Build">
      <include name="**/*.exe" />
      <include name="**/*.pdb" />
   </fileset>
</copy>

但是,我还将在liba,libb,...文件夹中获得*。pdb文件。

有什么方法我只能复制具有*。exe -file的PDB文件,与他们的兄弟姐妹相同的目录?
不幸的是,这些文件夹的命名不得以任何方式允许基于文件夹名称使用通配符。

当然,我可以单独列出每个文件,例如:

<include name="ProjA/*.pdb" />
<include name="Foo/*.pdb" />
<!-- ... -->

但是,我认为也许有一种优雅的方式可以指定“复制所有*。Exe exe 文件和所有**。 pdb在其旁边有*。exe文件的文件”。

I am trying to use ANT to copy some files of a C++ build into another directory.

The output of the build looks like this:

/Build
   /LibA
      LibA.lib
      LibA.pdb
   /LibB
      LibB.lib
      LibB.pdb
   /ProjA
      myexe.exe
      myexe.pdb
   /Foo
      foo.exe
      foo.pdb
   /...

Now, I would like to copy all *.exe files and their *.pdb files to another directory (but not the *.pdb files of the libs).

I tried with:

<copy todir="outdir">
   <fileset dir="Build">
      <include name="**/*.exe" />
      <include name="**/*.pdb" />
   </fileset>
</copy>

However, then I will also get the *.pdb files inside the LibA, LibB, ... folders.

Is there any way I can only copy the pdb-files which have an *.exe-file in the same directory as their sibling?
Unfortunately, the folders are not named in any way that would allow using wildcards based on the folder name.

Of course, I could list each file individually, such as:

<include name="ProjA/*.pdb" />
<include name="Foo/*.pdb" />
<!-- ... -->

However, I am thinking that maybe there is an elegant way where I can specify "copy all *.exe files and all *.pdb files which have an *.exe file next to them".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缺⑴份安定 2025-01-30 01:02:06

您可以使用选择器要查找“兄弟姐妹”文件,类似的内容:

<copy todir="outdir">
  <fileset dir="Build" includes="**/*.pdb">
    <present targetdir="Build">
      <mapper type="glob" from="*.pdb" to="*.exe" />
    </present>
  </fileset>
  <fileset dir="Build" includes="**/*.exe" />
  <flattenmapper />
</copy>

这只会复制具有匹配.EXE文件的.pdb文件。

为了使其简单,请为EXE文件使用单独的文件集。

仅当您只需要复制忽略源目录结构的文件时,才需要平坦的映射器。

You could use the <present> selector to find the "sibling" files, something like this:

<copy todir="outdir">
  <fileset dir="Build" includes="**/*.pdb">
    <present targetdir="Build">
      <mapper type="glob" from="*.pdb" to="*.exe" />
    </present>
  </fileset>
  <fileset dir="Build" includes="**/*.exe" />
  <flattenmapper />
</copy>

This will only copy the .pdb files with matching .exe files.

To keep it simple, use a separate fileset for the exe files.

The flatten mapper is only needed if you want to copy just the files ignoring the directory structure in the source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文