使用 Ant 复制子文件夹的内容 [英] Copy content of subfolders with Ant
问题描述
如何使用 Ant 复制给定文件夹的所有子文件夹的内容?
How can I copy content of all subfolders of given folder using Ant?
即我有这样的文件夹结构
i.e. I have such folder structure
folder/
folder/sub1/1.txt
folder/sub1/f1/1.txt
folder/sub2/2.txt
...
我不知道子文件夹的确切名称.而且我需要将所有文件中的内容复制到一个文件夹中(保持内容结构,即将所有文件复制到一个目录中使用 flatten 不是解决方案).我需要得到
I don't know exact names of subfolders. And I need to copy content from all of them into one folder (keeping the structure of content, i.e. copying all files into one dir using flatten isn't a solution). I need to get
newfolder/1.txt
newfolder/1/1.txt
newfolder/2.txt
...
fileset 是否允许以这种方式对子文件夹进行分组?**
代表零个或多个目录,不允许使用 *
作为目录名,即 <fileset dir="${dir}/*/"/>
不可接受.
Does fileset allows to group subfolders in such a way?
**
stands for zero or more directories, and usage of *
as directory name is disallowed, i.e. <fileset dir="${dir}/*/" />
isn't acceptable.
提前致谢,尤里
推荐答案
<copy toDir="newfolder">
<fileset dir="folder">
<include name="*/**"/>
<exclude name="*"/>
</fileset>
<regexpmapper from="^[^/]*/(.*)$$" to="\1" handledirsep="true"/>
</copy>
如果您打算在 Windows 中运行此脚本,则只需指定 handledirsep
.
You only need to specify handledirsep
if you ever intend to run this script in Windows.
这篇关于使用 Ant 复制子文件夹的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!