如何蚂蚁复制过程中剥离一个文件夹 [英] How to strip one folder during Ant copy

查看:156
本文介绍了如何蚂蚁复制过程中剥离一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有文件路径,如LibraryX / A /东西/ FileY.txt,我用在Ant构建includesfile其中的文件。不过,我需要在复制过程中删除LibraryX / A /路径的一部分:文件会从LibraryX / A /东西/ FileY.txt复制和土地成东西/ FileY.txt 。我看着几个regexpmappers,但还没有与他们取得任何成功可言。 :/

I have a file which has filepaths like "LibraryX/A/Stuff/FileY.txt", which I'm using as includesfile in Ant build. However, I'm in need of removing the "LibraryX/A/" part of the path DURING the copy process: The file gets copied from "LibraryX/A/Stuff/FileY.txt" and lands into "Stuff/FileY.txt". I've looked into few regexpmappers but haven't had any success with them at all. :/

这样做的目的是,目标文件夹可以自定义文件中的东西/ MoreStuff覆盖了,我想用覆盖=假,以保持磁盘访问到最小,并保持自定义文件完好无损。

The purpose for this is that the target folder can have custom files in "Stuff/MoreStuff" overwritten, and I want to use the overwrite="false" to keep the disk access into minimum and keeping the custom files intact.

蚂蚁:

<copy todir="C:/targetdir/" overwrite="false">
    <fileset dir="C:/sourcedir/">
        <includesfile name="C:/targetdir/includes.file" />
    </fileset>
</copy>

Includes.file:

Includes.file:

LibraryX/A/Stuff/FileA.txt
LibraryX/A/Stuff/FileB.txt
LibraryX/A/Stuff/FileC.txt
LibraryX/A/Stuff/FileY.txt

Sourcedir:

Sourcedir:

sourcedir/LibraryX/A/Stuff/FileA.txt
sourcedir/LibraryX/A/Stuff/FileB.txt
sourcedir/LibraryX/A/Stuff/FileC.txt
sourcedir/LibraryX/A/Stuff/FileY.txt

目标目录:

targetdir/Stuff/FileY.txt

现在,所有的的东西的-folder在的 sourcedir 的,应该结束进入的的东西的-folder中的 TARGETDIR 。但如何?

Now, all the files in Stuff -folder at sourcedir, should end into the Stuff -folder in targetdir. But how?

奖励:如果我将文件从TARGETDIR / LibraryX / A /东西之举,他们将覆盖在TARGETDIR /资料文件夹中的一切,甚至与覆盖=假。 presumably因为他们比在东西文件夹中的那些目前。

Bonus: If I move the files from "targetdir/LibraryX/A/Stuff", they will overwrite everything in the "targetdir/Stuff" folder, even with the overwrite="false". Presumably because they are newer files than the ones in the Stuff folder currently.

注意:我当然可以,将自定义文件从目标目录了,在复制的东西,然后将自定义文件后面,覆盖新的。但这个访问磁盘颇多,放慢的过程。

Note: I could, of course, move the custom files away from the target directory, copy the stuff over and then move the custom files back, overwriting the new ones. But this accesses the disk quite a lot, slowing down the process.

推荐答案

使用Ant v1.8.2的开始,你可以使用 cutdirsmapper 来剥去文件目录领先一定数量的路径。请参阅映射器类型文档的最底部。

Starting with Ant v1.8.2 you can use the cutdirsmapper to strip some number of leading directories from file paths. See the very bottom of the mapper type docs.

<copy todir="C:/targetdir/" overwrite="false">
    <fileset dir="C:/sourcedir/">
        <includesfile name="C:/targetdir/includes.file" />
    </fileset>
    <cutdirsmapper dirs="2"/>
</copy>

奖励::您可以使用触摸 Ant任务,使所有在TARGETDIR比所有的源文件更新,因此被覆盖prevent其中的文件。

Bonus: You could use the touch ant task to make all the files in targetdir newer than all the source files and therefore prevent them from being overwritten.

这篇关于如何蚂蚁复制过程中剥离一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆