问题描述
如何使用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 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复制子文件夹的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!