Ant - determine file size

A

Andrew Thompson

I would like to add the file size to a variety of JNLP
(XML) files that are generated by ant, as are the
(Jar) files themselves.

It confounds me that there seems to be no way in
ant, to retrieve the size of a file as an integer figure
of bytes.

Did I miss something? Either that provides that
functionality, or in the way ant works/is supposed to
work (e.g. write a custom task).

(BTW - ideally I am after an X-plat way, but for my own
purposes, even something 'exec' for Win. XP will do..)

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
 
G

Gordon Beaton

It confounds me that there seems to be no way in ant, to retrieve
the size of a file as an integer figure of bytes.

I don't think it's a something often needed by a typical build.
Did I miss something? Either that provides that functionality, or in
the way ant works/is supposed to work (e.g. write a custom task).

I've never done this myself, but implementing a new task doesn't look
all that intimidating:

<taskdef name="FileSize" classname="org.whatever.FileSize"/>

Then do something simple with java.io.File.length()?

/gordon

--
 
D

Daniel Dyer

I would like to add the file size to a variety of JNLP
(XML) files that are generated by ant, as are the
(Jar) files themselves.

It confounds me that there seems to be no way in
ant, to retrieve the size of a file as an integer figure
of bytes.

Did I miss something? Either that provides that
functionality, or in the way ant works/is supposed to
work (e.g. write a custom task).

(BTW - ideally I am after an X-plat way, but for my own
purposes, even something 'exec' for Win. XP will do..)

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

Since Ant 1.6.3.

Dan.
 
A

Andrew Thompson

Gordon said:
I don't think it's a something often needed by a typical build.

I was beginning to suspect that. Daniel's pointer to
the introduction of it in 1.6.3 supports that even more,
in that it seems rather later to be introducing something
which is imperative for a good build tool.
I've never done this myself, but implementing a new task doesn't look
all that intimidating:

I had implemented a custom task for the saverbeans project.
As you suspect - it is not that tricky. But another thing I
forgot to menion was that I wanted these build files (in the
best situation) to be available to anyone running Ant (1.n.n+),
and introducing custom tasks complicates that.

I think I'll go with Daniel's suggestion and 1.6.3+.

Thanks for the input.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
 
A

Andrew Thompson

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top