Using ant, rename a directory without knowing the full path?

Posted by mixonic on Stack Overflow See other posts from Stack Overflow or by mixonic
Published on 2010-04-06T17:48:03Z Indexed on 2010/04/06 18:23 UTC
Read the original article Hit count: 246

Filed under:
|
|
|
|

Howdy friends,

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.

Thanks much, -Matt

© Stack Overflow or respective owner

Related posts about ant

Related posts about java