2013-10-23 29 views
2

我想在ANT中移动一些文件,但无法弄清楚如何去做。我知道如何以顺序方式做到这一点,但无法弄清楚这种做法的“蚂蚁方式”。基于他们在的文件夹移动和重命名文件

./<language>/<FileName>.properties 

到:

从移动文件

./<FileName>_<language>.properties 

因此,例如,我有:

./fr/file1.properties 
./fr/file2.properties 
./fr/file3.properties 
./en/file1.properties 
./en/file2.properties 
./en/file3.properties 
./ko/file1.properties 
./ko/file2.properties 
./ko/file3.properties 

我需要移动这些了一个目录和重命名文件像这样:

./file1_fr.properties 
./file2_fr.properties 
./file3_fr.properties 
./file1_en.properties 
./file2_en.properties 
./file3_en.properties 
./file1_ko.properties 
./file2_ko.properties 
./file3_ko.properties 

有没有一种简单的方法来做这个映射在蚂蚁?我不知道我会支持哪些语言或文件名是什么。

在bash中这将是直截了当的。我会做这样的事情:

find ./* -maxdepth 0 -type d | while read DIR; do 
      # */ Correct syntax highlighting 

    find $DIR -maxdepth 0 -type f | while read FILE; do 

     # Note: this would produce file1.properties_fr 
     # which isn't exactly right. Probably need to 
     # use sed to remove and add .properties. 
     mv $DIR/$FILE ./$FILE_$DIR 

    done; 
done; 

回答

2

move任务使用正则表达式mapper

<target name="rename"> 
    <move todir="."> 
    <fileset dir="."> 
     <include name="**/*.properties" /> 
    </fileset> 
    <mapper type="regexp" from="([^/]*)/([^/]*)(\.properties)$" to="\2_\1\3" /> 
    </move> 
</target> 
+0

只是打我!只是想通了。承诺我的代码,只是检查回来,看看有没有人回答。 – sixtyfootersdude

相关问题