ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Halstead, Chris" <Chris.Halst...@delta.com>
Subject RE: Renaming a directory when the source directory is not known
Date Tue, 15 Apr 2003 17:41:36 GMT
Many thanks to Seb...I finally have it working.  Here is the winner:

  <!-- Prep for deployment -->
  <target name="PREP">

        <path id="output.path">
                <dirset dir="${output.dir}">
                        <include name="*" />
                </dirset>
        </path>

        <pathconvert targetos="unix" property="real.path" refid="output.path"/>

        <basename property="dynamic.dir" file="${real.path}"/>

        <echo message="Dynamically created directory is ${dynamic.dir}"/>

        <move todir="${output.dir}/newname">
                <fileset dir="${output.dir}/${dynamic.dir}"/>
        </move>

  </target>


Thanks again Seb, this was a real stumper!

-chris

Sebastien Blanc wrote:
> 
> oops, you don't know the name of the file at that time.
> then why not building a fileset '*' of what is under your 
> output directory, then converting it into a property (with 
> pathconvert or so) as if you wanted to print this fileset and 
> here you have your directory name dynamically.
> let me know if this is enough clear,
> seb.
> 
> Sebastien Blanc wrote:
> 
> > ok. so you can do a move as u did, the only remaining pb 
> beeing to dynamically get the name of the directory for your 
> archive into a property.
> > how about the dirname task ?
> > seb.
> >
> > "Halstead, Chris" wrote:
> >
> > > Seb - Thanks again for all your help.  Your example works 
> just fine, but the problem is that the source directory won't 
> always be named 'foo'.  I need a way to do what the code 
> snippet below does without having to know that the directory 
> is named 'foo' beforehand.
> > >
> > > What I'm trying to accomplish is this: when I extract a 
> ZIP archive to the output dir I end up with something like 
> /output/archive-1.2.3.  I want to change it to be 
> /output/archive without having to know that the original was 
> named 'archive-1.2.3'.
> > >
> > > Thanks,
> > >
> > > -chris
> > >
> > > >
> > > > Chris,
> > > > I just did the following test:
> > > > <?xml version="1.0"?>
> > > > <project name="test move" default="main">
> > > >
> > > > <property name="output.dir" value="somedir" />
> > > > <property name="target" value="bar" />
> > > >
> > > > <target name="mv">
> > > >
> > > >   <move todir="${output.dir}/${target}">
> > > >     <fileset dir="${output.dir}/foo">
> > > >     </fileset>
> > > >   </move>
> > > > </target>
> > > >
> > > >  </project>
> > > >
> > > > and somedir/foo directory is moved to somedir/bar directory
> > > > just fine (having recursive content in foo at the beginning).
> > > > am I missing smthg ? if ur example it looks to me you move
> > > > somedir directory to somedir/bar directory which would be
> > > > somewhat a bit difficult. [also are u sure the ${target}
> > > > property is defined properly when your PREP target is called
> > > > ? if the pattern is erroneous then the mapper will not 
> do anything.]
> > > >
> > > > FYI <mapper> cd then be embedded into the fileset to map the
> > > > new files to new directory or names but looking at your need
> > > > the above is enough.
> > > >
> > > > hope this will help, maybe add an echo "mv-ing ${your_from}
> > > > to ${your_to}" before the call to <move> to see what is 
> happening.
> > > >
> > > > seb.
> > > >
> > >
> > > 
> >
> > 
> 
> 

Mime
View raw message