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

これらを 1 つ上のディレクトリに移動し、次のようにファイルの名前を変更する必要があります。

./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;
4

1 に答える 1

2

移動タスクで正規表現マッパーを使用します。

<target name="rename">
  <move todir=".">
    <fileset dir=".">
      <include name="**/*.properties" />
    </fileset>
    <mapper type="regexp" from="([^/]*)/([^/]*)(\.properties)$" to="\2_\1\3" />
  </move>
</target>
于 2013-10-23T19:11:07.820 に答える