• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

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.
0
mdoland
Asked:
mdoland
  • 6
  • 2
1 Solution
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
CEHJCommented:
If you know the extension, you can use

http://ant.apache.org/manual/CoreTasks/basename.html
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now