build.xml
<?xml version="1.0" encoding="UTF-8"?>
<target name="pathConvertor" description="">
<pathconvert property="convertedDir">
<dirset dir=".">
<patternset id="convdir">
<include name="**/java/**"/>
<include name="**/resources/**"/>
</patternset>
</dirset>
<mapper>
<filtermapper>
<replacestring from="java" to="replaced"/>
<replacestring from="resources" to="replaced"/>
</filtermapper>
</mapper>
</pathconvert>
<script language="javascript"><![CDATA[
var toDir = project.getProperty("convertedDir");
var dirs = toDir.split(";");
var size = dirs.length;
var mkdir = project.createTask("mkdir");
for (var i = 0; i < size; i++) {
var targetDir = dirs[i];
mkdir.setDir(new java.io.File(targetDir));
mkdir.perform();
}
]]></script>
</target>
</project>
実行結果
e:\work\ant>ant pathConvertor
Buildfile: e:\work\ant\build.xml
pathConvertor:
[mkdir] Created dir: e:\work\ant\dir\replaced
[mkdir] Created dir: e:\work\ant\path\to\example\replaced
[mkdir] Created dir: e:\work\ant\src\main\replaced
[mkdir] Created dir: e:\work\ant\src\test\replaced
BUILD SUCCESSFUL
Total time: 2 seconds
e:\work\ant>tree
フォルダー パスの一覧
ボリューム シリアル番号は 00000200 A0FE:B066 です
E:.
├─dir
│ ├─java
│ ├─replaced
│ └─resources
├─path
│ └─to
│ └─example
│ ├─java
│ └─replaced
└─src
├─main
│ ├─java
│ ├─replaced
│ └─resources
└─test
├─java
├─replaced
└─resources