bash - 根据文件所在的文件夹移动和重命名文件

标签 bash ant

我正在尝试在 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;

最佳答案

使用正则表达式mappermove任务:

<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/

相关文章:

linux - 在 bash 脚本中调用 SSH Sudo 命令

java - 在 eclipse 中从 .class 文件构建可执行 jar 文件

git - 用于检查指定的 Git 分支是否存在的 Shell 脚本?

linux - bash: cd: 没有那个文件或目录

java - Ant 与JAXB : add "extension" and make generated classes "serializable"

java - 打包 jar 时会导致 'Could not find the main class' 的原因是什么?

java - 指针在android中混淆

java - 如何检查源代码中是否存在禁用词 extGWT

bash - 变量函数bash中的特殊字符

ruby-on-rails - 在 bash 中执行 rake 命令