9

不明なディレクトリを持つ zip ファイルが与えられた場合、そのディレクトリの名前を変更したり、正規化されたパスに移動したりするにはどうすればよいですか?

<!-- Going to fetch some stuff -->
<target name="get.remote">

    <!-- Get the zipfile -->
    <get src="http://myhost.com/package.zip"
         dest="package.zip"/>

    <!-- Unzip the file -->
    <unzip src="package.zip"
           dest="./"/>

    <!-- Now there is a package-3d28djh3 directory.  The part after package- is
         a hash and cannot be known ahead of time -->

    <!-- Remove the zipfile -->
    <delete file="package.zip"/>

    <!-- Now we need to rename "package-3d28djh3" to "package".  My best attempt
         is below, but it just moves package-3d28djh3 into package instead of
         renaming the directory. -->

    <!-- Make a new home for the contents. -->
    <mkdir dir="package" />

    <!-- Move the contents -->
    <move todir="package/">
      <fileset dir=".">
        <include name="package-*/*"/>
      </fileset>
    </move>

</target>

私はアリのユーザーではありません。どんな洞察も役に立ちます。

どうもありがとう - マット

4

2 に答える 2

13

これは、dirset が 1 つのアイテムのみを返す場合にのみ機能します。

<project name="Test rename" basedir=".">

  <target name="rename">
    <path id="package_name">
      <dirset dir=".">
        <include name="package-*"/>
      </dirset>
    </path>
    <property name="pkg-name" refid="package_name" />
    <echo message="renaming ${pkg-name} to package" />
    <move file="${pkg-name}" tofile="package" />
  </target>

</project>
于 2010-04-06T18:18:09.307 に答える
2

package-3d28djh3 ディレクトリ内にサブディレクトリがない場合 (または、抽出後に呼び出されたもの) を使用できます

<move todir="package" flatten="true" />
  <fileset dir=".">
    <include name="package-*/*"/>
  </fileset>
</move>

それ以外の場合は、移動タスクに正規表現マッパーを使用して、package-xxx ディレクトリを削除します。

<move todir="package">
  <fileset dir=".">
    <include name="package-*/*"/>
  </fileset>
  <mapper type="regexp" from="^package-.*/(.*)" to="\1"/>
</move>
于 2010-04-06T18:34:26.757 に答える