9

给定一个带有未知目录的 zipfile,我如何重命名或将该目录移动到规范化路径?

<!-- 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 回答