Ant - Change extension on file

I have an exec in Ant that looks like this:

<exec taskname = "convert"
executable = "convert"
failonerror = "true">
<arg line="in=@{file} out=???" />
</exec>

I want to use a command that converts a file. The in infile name has one extension and the out file another, but the rest of the file name should be the same. How do I get it this way?

The arg line is messed up since I don't know what to write.
mdolandAsked:
Who is Participating?
 
CEHJCommented:
If you know the extension, you can use

http://ant.apache.org/manual/CoreTasks/basename.html
0
 
CEHJCommented:
You could use a property for the name up to the extension
0
 
CEHJCommented:
<arg line="in=@${file.without.extension}.in" out="${file.without.extension}.out" />
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
CEHJCommented:
Actually that should maybe be more like:

<arg line="in=${file.without.extension}.in" />
<arg line="out=${file.without.extension}.out" />

but i think you probably get the general principle
0
 
objectsCommented:
try:

<arg line="in=${file}.in out=${file}.out" />
0
 
CEHJCommented:
Each argument should be tagged separately (that's what they're for)
0
 
mdolandAuthor Commented:
It sounds straight, but this is the way it looks outside:

<for param="file">
                              <!-- Perform encoding for all files included in the fileset specified by the macro attributes -->
                              <path>
                                    <fileset dir="@{dir}">
                                          <include name="@{includes}" />
                                          <exclude name="@{excludes}" />
                                    </fileset>
                              </path>
                              <sequential>
                                    <exec      taskname      = "convert"
                                                executable      = "convert"
                                                failonerror      = "true">
                                          <arg line="in=@{file} out=???" />

                                    </exec>
                                    <!-- Remove files if keeporiginals attribute is not set to true -->
                                    <if>
                                          <equals arg1="@{keeporiginals}" arg2="false" casesensitive="false" />
                                          <then>
                                                <delete quiet="true" file="@{file}" />
                                          </then>
                                    </if>
                              </sequential>
</for>



I get it in as a filesset from an include statement, but I don't get it how I should do to get the extension off there.
0
 
objectsCommented:
if you know the output extension the using basename mentioned by cehj would allow you to do:


<basename property="filebase" file="${file}"/>
<arg line="in=@{file} out=${filebase}.out" />
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.