使用Ant,重命名不知道完整路径的目录? [英] Using ant, rename a directory without knowing the full path?

查看:105
本文介绍了使用Ant,重命名不知道完整路径的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到与未知目录中的zip文件,我怎么可以重命名或移动目录到一个标准化的路径?

Given a zipfile with an unknown directory, how can I rename or move that directory to a normalized path?

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

我没有太多的蚂蚁用户,任何见解将是有益的。

I'm not much of an ant user, any insight would be helpful.

谢谢了,-Matt

推荐答案

这只会只要dirset只返回1项工作。

This will only work as long as the dirset only returns 1 item.

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

这篇关于使用Ant,重命名不知道完整路径的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆