ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Manoj Sadangi <msada...@manh.com>
Subject RE: Problem with deleting a file inside javascript
Date Thu, 05 Jun 2003 13:34:28 GMT
looks like a neat solution .I will try this

thanks, 
manoj 



-----Original Message-----
From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
Sent: Thursday, June 05, 2003 3:08 AM
To: user@ant.apache.org
Subject: AW: Problem with deleting a file inside javascript


I don┬┤t know why this occured, but that worked: create a <delete> task 
for the deletion:


    <target name="delete">
        <mkdir dir="4delete"/>
        <copy todir="4delete"><fileset dir="test"/></copy>

        <!-- for what files the size is required? -->
        <fileset id="fs" dir="4delete"/>

        <!-- use java.io.File in script task for getting that size -->
        <script language="javascript"> <![CDATA[

            // iterate over the files selected by the fileset defined above
            // code adapted from copy task implementation

            // Get the DirectoryScanner
            // project is an object defined by script task
            ds = fs.getDirectoryScanner(project);

            // Get the source files (array)
            srcFiles = ds.getIncludedFiles();

            // Create a <delete> task
            del = project.createTask("delete");         // <-------------

            // iterate over that array
            for (i=0; i<srcFiles.length; i++) {
                filename = srcFiles[i];
                file = new java.io.File(fs.getDir(project), filename);
                size = file.length();

                if (size <= 15) {
                    del.setFile(file);          // <-------------
                    del.perform();              // <-------------
                }
            }
        ]]> </script>
    </target>




Jan

> -----Urspr├╝ngliche Nachricht-----
> Von: Manoj Sadangi [mailto:msadangi@manh.com]
> Gesendet am: Mittwoch, 4. Juni 2003 16:03
> An: 'Ant Users List'
> Betreff: Problem with deleting a file inside javascript
> 
> How can I delete a file inside javascript?
> This is throwing error in the line f.delete() "missing name after .
> operator"
> <script language="javascript"> <![CDATA[ 
> importClass(java.io.File);
>         f = File("test.txt");
>         fsize = f.length();
>        if(fsize <= 15)
>         {
>           f.delete();      
>         }  
> ]]> </script>
> 
> thanks, 
> manoj 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

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


Mime
View raw message