我正在尝试在 ANT 中移动一些文件,但不知道该怎么做。我知道如何按顺序执行此操作,但无法找出“ 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
有没有一种简单的方法可以在 ant 中进行这种映射?我不知道我将支持哪些语言或文件名可能是什么。
在 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;
最佳答案
<target name="rename">
<move todir=".">
<fileset dir=".">
<include name="**/*.properties" />
</fileset>
<mapper type="regexp" from="([^/]*)/([^/]*)(\.properties)$" to="\2_\1\3" />
</move>
</target>
关于bash - 根据文件所在的文件夹移动和重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19549020/