gpt4 book ai didi

Ant:将相同的文件集复制到多个位置 - 继续

转载 作者:行者123 更新时间:2023-12-04 15:36:55 27 4
gpt4 key购买 nike

我的问题是这个线程的延续:
Ant: copy the same fileset to multiple places

我是映射器的新手。有人(carej?)可以分享一个使用映射器来做到这一点的例子吗?这是我正在尝试的:

parent_folder    |----child1_folder    |         |----files    |                |----config.file    |                |----data.txt    |----child2_folder    |----child3_folder    .    .    .    |----childn_folder

I don't have the option to use ant-contrib (sorry ... the ant location or any taskdesf isn't under my control). So I don't know how to loop over the uncertain number of folders.

Restrictions on me:

  1. I only know the name of child1_folder (don't know names of the other children)
  2. Number of other children is uncertain
  3. I am expected to create the files folder under each child folder (via another task, if not copy).

Here is what I was trying for (currently trying for a single file, will extend with additional mappers once this starts to work):

<copy todir="/tmp/parent_folder" verbose="true">
<fileset dir="/tmp/parent_folder">
<include name="*/files/config.file"/>
</fileset>
<mapper type="glob" from="*/files/config.file" to="*/files/config.file"/>
</copy>

一直说 skipped - don't know how to handle it其次是 No sources found. .

提前致谢,
帕拉格·多克

另一个(可能?)相关问题:
Using mapper & fileset to copy files into a different subdirectory?

最佳答案

这是一种方法的示例。主要特点是使用 enablemultiplemappings在复制任务中,还有一个 scriptmapper处理迭代目标目录。映射器链用于使提供给脚本映射器的源只是要复制的文件相对于目标目录的路径。

<property name="src.dir" value="child1_folder" />

<dirset dir="parent_folder" id="target.dirs">
<include name="*" />
<exclude name="${src.dir}" />
</dirset>

<copy todir="parent_folder" enablemultiplemappings="yes">
<fileset dir="parent_folder">
<include name="${src.dir}/**"/>
</fileset>
<chainedmapper>
<globmapper from="${src.dir}/*" to="*" />
<scriptmapper language="javascript">
<![CDATA[
// Obtain a reference to the dirset
var dirSet = project.getReference( "target.dirs" );

// Now get matching dirs.
var ds = dirSet.getDirectoryScanner( project );
var includes = ds.getIncludedDirectories( );
for ( var i = 0; i < includes.length; i++ )
{
self.addMappedName( includes[i] + "/" + source );
}
]]>
</scriptmapper>
</chainedmapper>
</copy>

自 1.6 版以来,复制任务中的多重映射已在 Ant 中出现。

关于Ant:将相同的文件集复制到多个位置 - 继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6120175/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com