Are there return values for the macro saveAs

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

Are there return values for the macro saveAs

Justin McGrath
When I do:
saveAs("Measurements", results_file);

can I get a return value for whether it succeeded? I get errors when I
try to do something like:
error = saveAs("Measurements", results_file);

The definition doesn't mention a return value, but I thought it was
good practice to check whether the save worked before moving on to
other stuff.

Also, I would like to have a backup of the last file but I can't seem
to work.  I tried this:
macro "Save results file [F4]" {
        error = 1;
        if ( results_file == '\0' )
                exit("Select a working directory");
        if ( File.exists(results_file) ) {
                print("Renaming "+results_file+" to "+results_file+".backup");
                File.delete(results_file+".backup");
                error = File.rename(results_file,results_file+".backup");
        }
       
        if ( error != 0 ) {
                print("Saving "+results_file);
                saveAs("Measurements", results_file);
        } else {
                print("Error saving results file");
        }
}

But File.delete tells me I can only delete certain files, which is in
the definition of the macro so I should have expected that.  However,
I can't figure out a way to keep a backup, since File.rename won't
overwrite the old file.  How have others done this?

Thanks,
Justin
Reply | Threaded
Open this post in threaded view
|

Re: Are there return values for the macro saveAs

Michael Schmid
On 9 May 2007, at 16:44, Justin McGrath wrote:

<snip>
> But File.delete tells me I can only delete certain files, which is in
> the definition of the macro so I should have expected that.  However,
> I can't figure out a way to keep a backup, since File.rename won't
> overwrite the old file.  How have others done this?

Hi Justin,

maybe an answer to part 2 of your question above: For File.delete it
is enough if the string "ImageJ" is somewhere in the path.

So you can also delete a file in, e.g.,
   /home/justin/data/myImageJresults/sample003/

An alternative would be creating a new backup each time, e.g.,
   while (File.rename(results_file,results_file+getTime()) == 0)
   wait(1);

(the while loop just in case you create two backups within a
millisecond)

Michael