file.delete()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

file.delete()

Lionel Flandin-2
Hin everyone,

I would like to use the file.delete() macro, but could not get it to work.
Here is an example of the code :

        var todelete="/sim/spicy/IJ/save/1.txt";
        if (File.exists(todelete)) {
                File.delete(todelete);
                print ("found and deleted");}
        else {print ("not found");}

I get the following error : "File must be in imageJ home or temp
directory in line 3".

any idea ?

Thanks in advance,

Lionel
Reply | Threaded
Open this post in threaded view
|

Re: file.delete()

dscho
Hi,

On Wed, 14 Feb 2007, Lionel Flandin wrote:

> var todelete="/sim/spicy/IJ/save/1.txt";
> if (File.exists(todelete)) {
> File.delete(todelete);
> print ("found and deleted");}
> else {print ("not found");}
>
> I get the following error : "File must be in imageJ home or temp
> directory in line 3".

This is a security feature. Otherwise any macro you run could destroy
_all_ your files.

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: file.delete()

Michael Schmid
In reply to this post by Lionel Flandin-2
Hi Lionel,

ImageJ checks the file path to avoid deleting files in
arbitrary directories. I am happy about this since it reduces
the risk of ImageJ Macros deleting everything on my harddisk.
(fortunately, I have not heard about ImageJ Macro viruses ;-)

See the sourcecode at
http://rsb.info.nih.gov/ij/developer/source/ij/macro/Functions.java.html

What you could do is put the string "ImageJ" into the path, e.g.,
       var todelete="/sim/spicy/ImageJ/save/1.txt";

Michael
________________________________________________________________

On 14 Feb 2007, at 16:40, Lionel Flandin wrote:

> Hin everyone,
>
> I would like to use the file.delete() macro, but could not get it  
> to work.
> Here is an example of the code :
>
> var todelete="/sim/spicy/IJ/save/1.txt";
> if (File.exists(todelete)) {
> File.delete(todelete);
> print ("found and deleted");}
> else {print ("not found");}
>
> I get the following error : "File must be in imageJ home or temp  
> directory in line 3".
>
> any idea ?
>
> Thanks in advance,
>
> Lionel