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

发布于 2024-11-09 17:15:37 字数 1329 浏览 4 评论 0原文

我的问题是该线程的延续: Ant:将相同的文件集复制到多个位置

我是新人给地图绘制者。有人(carej?)可以分享一个使用映射器来执行此操作的示例吗?这就是我正在尝试的:

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

我没有使用 ant-contrib 的选项(抱歉...... ant 位置或任何 taskdesf 不在我的控制之下)。所以我不知道如何循环不确定数量的文件夹。

对我的限制:

  1. 我只知道 child1_folder 的名称(不知道其他子文件夹的名称)
  2. 其他子文件夹的数量不确定
  3. 我需要在每个子文件夹下创建 files 文件夹(通过另一个子文件夹)任务,如果不是复制)。

这是我正在尝试的(目前正在尝试单个文件,一旦开始工作,将使用额外的映射器进行扩展):

<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 后面跟着 <代码>未找到来源。。

提前致谢, Parag Doke

另一个(可能?)相关问题: 使用映射器和文件集将文件复制到不同的子目录中?

My question is in continuation of this thread:
Ant: copy the same fileset to multiple places

I am new to mappers. Can someone (carej?) kindly share an example of using the mapper to do this ? Here is what I am trying for:

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>

It keeps saying skipped - don't know how to handle it followed by No sources found..

Thanks in advance,
Parag Doke

Another (possibly?) related question:
Using mapper & fileset to copy files into a different subdirectory?

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

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

发布评论

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

评论(1

音盲 2024-11-16 17:15:37

这是一种方法的示例。主要功能是在复制任务中使用 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 中已包含复制任务中的多个映射。

Here's an example of one way. The key features are the use of enablemultiplemappings in the copy task, and a scriptmapper to deal with iterating over the target directories. A mapper chain is used to make the source that is provided to the scriptmapper be just the path of the file to be copied relative to the target directory.

<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>

Mulitple mappings in the copy task have been in Ant since version 1.6.

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