ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steffen Schluff" <schl...@oio.de>
Subject AW: file size
Date Tue, 19 Nov 2002 10:43:29 GMT
The task below was once published by Sun when building J2ME-MIDP
Applications, hope it helps.

Best wishes

Steffen Schluff

OIO - Orientation in Objects GmbH


----------------------------------------

--- Usage example ---

<!-- Define the task -->
<taskdef name="filesize" classname="ant.FileSizeTask"/>

<!-- Invoke the task -->
<filesize file="${my.file}" property="my.file.size"/>

<!-- Use the task's output -->
<echo message="Size of '${my.file}' is ${my.file.size} Bytes."/>




--- Here is the task's code ---

/*
 * Copyright 2001 by Sun Microsystems, Inc.,
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * All rights reserved.
 */
package ant;

import java.io.*;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
 * Simple task set a property to the size of a file.
 * It has two attributes, the file name and
 * the property name. The property set to the empty string
 * if the file does not exist.
 */

public class FileSizeTask extends Task {
    File file;
    String property;

    // The method executing the task
    public void execute() throws BuildException {
	if (property != null && property.length() > 0) {
	    if (file.exists()) {
		int size = (int)file.length();
		project.setProperty(property, Integer.toString(size));
	    } else {
		project.setProperty(property, "");
	    }
	}
    }

    // The setter for the "message" attribute
    public void setFile(File file) {
	this.file = file;
    }

    // The setter for the "property" attribute
    public void setProperty(String prop) {
	property = prop;
    }

}

------




-----Urspr√ľngliche Nachricht-----
Von: mm [mailto:mm@cleverlance.com]
Gesendet: Dienstag, 19. November 2002 11:38
An: ant-user@jakarta.apache.org
Betreff: file size


hi,

is there a way how to find size in byte of specified file through some ant
task and not exec.. ?

thanks
mirek mocek


--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message