如何在 Ant 中创建由映射器指定的目录 [英] How to create directories specified by a mapper in Ant
问题描述
给定一个文件集
<fileset id="myFiles" dir=".">
<include name="**/*.file"/>
</fileset>
如何在集合中的每个文件中创建一个子目录,以不带扩展名的文件名命名?
How do I create a sub-directory at each file in the set, named after the filename without the extension?
例如,给定文件folderA/X.file 和folderA/folderB/Y.file,我想创建目录folderA/X 和folderA/folderB/Y
For example, given the files folderA/X.file and folderA/folderB/Y.file, I want to create the directories folderA/X and folderA/folderB/Y
推荐答案
ant touch 任务支持创建文件、父目录和文件名映射,所以可以用来实现这个:
The ant touch task supports creating files, parent dirs and filename mapping, so can be used to achieve this:
<target name="mkdirs">
<touch mkdirs="true">
<fileset dir="the_dir"/>
<mapper type="glob" from="*.file" to="the_dir/*/.tmp" />
</touch>
<delete>
<fileset dir="the_dir" includes="**/.tmp"/>
</delete>
</target>
这会在目标目录中创建临时文件(如果目录不存在,则创建该目录),然后删除临时文件,留下您想要的目录.
This creates temporary files in target dirs (creating the dirs if the don't exist) then deletes the temporary files leaving the dirs you wanted.
这篇关于如何在 Ant 中创建由映射器指定的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!