2012-05-09 36 views
1

比方说,我有这样的目录结构:蚂蚁:重命名同名的子目录

  • 动物/狗/细节
  • 动物/ CAT /细节
  • 动物/青蛙/细节
  • 动物/马/细节

使用蚂蚁,我想重新命名animals下的所有子目录称为details现在被命名为new。所以结果会是这样:

  • 动物/狗/新
  • 动物/ CAT /新
  • 动物/青蛙/新
  • 动物/马/新

我我试过这样的事情:

<move tofile="new"> 
     <path id="directories.to.rename"> 
      <dirset dir="animals"> 
       <include name="**/details"/> 
      </dirset> 
     </path> 
    </move> 

但是得到这个错误:

Cannot concatenate multiple files into a single file. 
+0

可能重复http://stackoverflow.com/questions/1041213/how-to-rename-a-folder-using-ant –

+2

我不认为这涉及到矿山作为一个不与多个子处理-directories。 – digiarnie

回答

1

使用Ant-Contribfor任务和propertyregex任务。

<target name="test"> 
    <for param="detailsDir"> 
    <dirset dir="animals"> 
     <include name="**/details"/> 
    </dirset> 
    <sequential> 
     <propertyregex property="output.dir" input="@{detailsDir}" regexp="(.*)/details" replace="\1" /> 
     <move file="@{detailsDir}" toFile="${output.dir}/new" /> 
    </sequential> 
    </for> 
</target> 
+0

因为我的ant-contrib版本使用foreach(而不是for),所以我不得不做一些tweeking,但是你在那里工作的核心思想非常好。谢谢! – digiarnie

3

你可以进行你通过mapper来形容重命名。例如:

<move todir="animals"> 
    <dirset dir="animals" includes="**/details" /> 
    <globmapper from="*/details" to="*/new"/> 
</move> 

(有在move task docs结束一个类似的例子。)

你站起身看见了,因为你已经混动任务的单文件模式下的错误(TOFILE )与多文件模式。 由于move任务接受任何基于文件的资源收集(包括dirset),所以不需要将dirset嵌套在path中。