You are using a fileset by using <items>.  If you check the documentation,
you'll see that the <items> element is of type fileset.  This approach is
used a few places in NAnt and can be confusing - basically, fileset is a
type, and so any element in a task can be of this type without actually
having that name. (for example the <csc> task has a child element
<sources> which is also of type fileset.)

There are also a few specialisations of fileset such as the
assemblyfileset that are used in certain circumstances.
HTH,
Bill

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steve
Kapinos
Sent: 26 August 2008 16:20
To: nant-users@lists.sourceforge.net
Subject: Re: [NAnt-users] task/function to rename files with a prefix?

I got there via this method

        <target name="rename">  
        <foreach item="File" property="fileloop">  
                <in>
                <items basedir="./">
                        <include name="*.data"/>
                </items>
                </in>
                <do>
                        <move file="${fileloop}"
tofile="${testprefix}_${path::get-file-name(fileloop)}" />  
                </do>
        </foreach>  
        </target>  

What was confusing me a bit was, the example below worked with the
property name in the path function (filename below) but if I tried to
use it in a test echo command, it would say it was not defined.  It
wasn't defined by a property statement, only the foreach line.  It
didn't make sense to me why the property would work in one place, but
not another.  Once I defined the property ahead of time, I was able to
use anywhere in the fornext loop.

I still don't understand how I would use fileset above instead of items.


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steve
Kapinos
Sent: Tuesday, August 26, 2008 4:53 PM
To: nant-users@lists.sourceforge.net
Subject: [NAnt-users] task/function to rename files with a prefix?

I'm trying to grab a set of files from a directory, move it to another,
and prefix all the names with a variable as I move them.

My theory is to loop through each file with a fornext and use a fileset
to select my files.  However, I can not seem to get the fileset and
fornext to be happy.  The documentation for the 'in' parameter for
fornext is completely confusing.

Here is basically what I'm trying to start off

    <foreach item="File" property="filename">
                <in>
                        <fileset basedir="./">
                                <include name="*.data" />
                        </fileset>
                </in>
            <echo>${filename}</echo>
        </foreach>

This does not work because it says <in> does not support the nested
<fileset>.  The help page says
-----------
Nested Elements:
<in>
Stuff to operate in. Just like the in attribute, but supports more
complicated things like a <fileset> and such.
------------

If I leave off in, it complains as well.

Basically I'm trying to take all files in the current directory named
*.data and rename them p_*.data

I've found one blog post that lead me to this solution
  <foreach item="File" in="./" property="fileName">  
    <!-- If the file has the .data extension -->  
    <if test="${string::to-lower(path::get-extension(fileName)) ==
'.data'}">  
     <!-- Rename the file with prefix -->  
     <move file="${fileName}"
tofile="${path::combine(path::get-directory-name(fileName), 'p_' +
path::get-file-name(fileName))}" />  
    </if>  
   </foreach>  

Which works except, the if condition seems like it should be solved when
the set is created.. and while the scenario works with the constant 'p_'
in there, if I want to make p a property, it fails saying unexpected
token.  Why can't a property work there?  And why is 'filename' in the
path statements above listed without the $ ?

TIA!

-Steve


------------------------------------------------------------------------
-
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
 
IMPORTANT ANNOUNCEMENT    You may be interested to know that Avon Insurance
has moved to brand new office premises.  Our new address is now Avon Insurance 
plc, Avon House, Ryon Hill Park, Stratford-upon-Avon, CV37 0UY.

IMPORTANT 
The information contained in this e-mail and any attachments is intended for 
the addressee only
and may contain legally privileged or confidential information. If you are not 
the intended
recipient you must not use, disclose, copy, distribute, alter, or take any 
action in reliance
on the information and Avon Insurance plc will not accept liability for any 
loss or damage howsoever
arising, directly or indirectly in reliance on it and gives no warranty or 
representation as to its
accuracy or reliability. If you are not the addressee, please notify us 
immediately on 01789 202121*
and delete the material from your computer and destroy any copies.

Avon Insurance plc reserves the right to monitor and record incoming and 
outgoing email messages for
the purposes of investigating or detecting unauthorised use of its system and 
ensuring its effective operation.
Avon Insurance plc will not accept liability for any loss or damage as a result 
of any virus being passed on.

Avon Insurance plc (No. 209606).
Registered in England.
Registered Office: Tiddington Road, Stratford-upon-Avon, Warwickshire CV37 7BJ.
Authorised and regulated by the Financial Services Authority.
A member of the NFU Mutual group of companies and the Association of British 
Insurers.
For security and training purposes telephone calls may be recorded and 
monitored.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to