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