如何重新命名N档和N文件夹与ANT [英] How to rename n files and n folders with ANT
本文介绍了如何重新命名N档和N文件夹与ANT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何重命名N档和N文件夹与ANT?对于文件,我知道我能做到这样的; <一href=\"http://stackoverflow.com/questions/4224995/how-to-rename-n-files-with-ant-batch-job\">question
如何做同样的事情的文件夹?
有关如
设置文件夹(输入)
com.google.appengine.eclipse.sdkbundle_1.5.2.r37v201107211953
com.google.gdt.eclipse.designer.doc.user_2.3.2.r37x201107161328
com.google.gdt.eclipse.designer.hosted.2_0.webkit_win32_2.3.2.r37x201107161253
org.eclipse.acceleo.common_3.1.0.v20110607-0602.jar
输出:
com.google.appengine.eclipse.sdkbundle_1.5.2
com.google.gdt.eclipse.designer.doc.user_2.3.2
com.google.gdt.eclipse.designer.hosted.2_0.webkit_win32_2.3.2
org.eclipse.acceleo.common_3.1.0.jar
解决方案
有关复杂的操作,我使用的常规Ant任务。
下面的例子将重命名的文件和目录,使用常规的前pressions:
&LT;项目名称=演示默认为重命名&GT; &lt;目标名称=引导&GT;
&LT; MKDIR DIR =$ {}的user.home /蚂蚁/ lib目录下。/&GT;
&LT;获得DEST =$ {}的user.home /蚂蚁/ lib中/ Groovy的all.jar在。 src=\"http://search.maven.org/remotecontent?filepath=org/$c$chaus/groovy/groovy-all/2.0.6/groovy-all-2.0.6.jar\"/>
&LT; /目标与GT; &lt;目标名称=重命名&GT;
&LT;的taskdef NAME =常规类名=。组织codehaus.groovy.ant.Groovy/&GT; &LT;文件集ID =filesToBeRenamedDIR =构建/&GT;
&LT; dirset ID =dirsToBeRenamedDIR =构建/&GT; &LT;常规&GT;
project.references.filesToBeRenamed.each {
字符串origName =它
串了newName = origName.replaceAll(/ _ [0-9 \\。] + [A-Z0-9 \\ - ] + /,) 如果(origName!=了newName){
ant.move(文件:origName,TOFILE:了newName,详细:真)
}
} project.references.dirsToBeRenamed.each {
字符串origName =它
串了newName = origName.replaceAll(/ _ [0-9 \\。] + [A-Z0-9 \\ - ] + /,) 如果(origName!=了newName){
ant.move(文件:origName,TOFILE:了newName,详细:真)
}
}
&LT; /常规&GT;
&LT; /目标与GT;
&LT; /项目&GT;
注:
- 在引导的目标只需要运行一次。它将从Maven的下载Groovy的罐子中心
How to rename n files and n folders with ANT? For files I know I can do it like this; question
How to do the same thing for folders?
For e.g. Set of folders (Input)
com.google.appengine.eclipse.sdkbundle_1.5.2.r37v201107211953
com.google.gdt.eclipse.designer.doc.user_2.3.2.r37x201107161328
com.google.gdt.eclipse.designer.hosted.2_0.webkit_win32_2.3.2.r37x201107161253
org.eclipse.acceleo.common_3.1.0.v20110607-0602.jar
Output:
com.google.appengine.eclipse.sdkbundle_1.5.2
com.google.gdt.eclipse.designer.doc.user_2.3.2
com.google.gdt.eclipse.designer.hosted.2_0.webkit_win32_2.3.2
org.eclipse.acceleo.common_3.1.0.jar
解决方案
For complex operations I use the groovy ANT task.
The following example will rename your files and directories, using regular expressions:
<project name="demo" default="rename">
<target name="bootstrap">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/groovy-all.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.0.6/groovy-all-2.0.6.jar"/>
</target>
<target name="rename">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<fileset id="filesToBeRenamed" dir="build"/>
<dirset id="dirsToBeRenamed" dir="build"/>
<groovy>
project.references.filesToBeRenamed.each {
String origName = it
String newName = origName.replaceAll(/_[0-9\.]+[a-z0-9\-]+/, "")
if (origName != newName) {
ant.move(file:origName, tofile:newName, verbose:"true")
}
}
project.references.dirsToBeRenamed.each {
String origName = it
String newName = origName.replaceAll(/_[0-9\.]+[a-z0-9\-]+/, "")
if (origName != newName) {
ant.move(file:origName, tofile:newName, verbose:"true")
}
}
</groovy>
</target>
</project>
NOTES:
- The "bootstrap" target only needs to be run once. It will download the groovy jar from Maven central
这篇关于如何重新命名N档和N文件夹与ANT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文