We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Ant - Change extension on file

Medium Priority
348 Views
Last Modified: 2013-11-19
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.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
You could use a property for the name up to the extension
CERTIFIED EXPERT
Top Expert 2016

Commented:
<arg line="in=@${file.without.extension}.in" out="${file.without.extension}.out" />
CERTIFIED EXPERT
Top Expert 2016

Commented:
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
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
try:

<arg line="in=${file}.in out=${file}.out" />
CERTIFIED EXPERT
Top Expert 2016

Commented:
Each argument should be tagged separately (that's what they're for)

Author

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.
CERTIFIED EXPERT
Top Expert 2016
Commented:
If you know the extension, you can use

http://ant.apache.org/manual/CoreTasks/basename.html

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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" />
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.