java - 使用 ant,在不知道完整路径的情况下重命名目录?

标签 java ant zip rename move

给定一个包含未知目录的 zip 文件,我如何重命名该目录或将该目录 move 到规范化路径?

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

我不是 ant 用户,任何见解都会有所帮助。

非常感谢,-马特

最佳答案

这仅在 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>

关于java - 使用 ant,在不知道完整路径的情况下重命名目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2587048/

相关文章:

java - 如何从数据库中的多个表中获取公共(public)列?

java - 使用 Apache CXF 时,org.bouncycaSTLe.asn1.x509.SubjectPublicKeyInfo 出现 NoClassDefFoundError

ant - JMeter:我如何将示例请求分组为一个测试用例,以便报告看起来整洁

c# - C# 中 ionic zip 的替代品是什么?

java: 更改 ZipEntry 名称

java - Java 中的引用是如何工作的?

java - 为什么我的 JsonObjectRequest 不工作?

javascript - 无法使用 Ant 在 Javascript 或 Jython 中创建 XSLT 扩展

java - 从项目中删除未使用的 jar

python - 按星期几对数据进行分类 Python