how to get name of arbitrary file selected by user in macro?

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

how to get name of arbitrary file selected by user in macro?

Bill Christens-Barry
How can I get the name and path of a text file opened by the user in a macro?The macro opens the
file this way:

f = File.openAsString("");

After looking at the list archives and online doc, I haven't figured out how to get at the name or path
when they are not already known. Note that I am opening a text file and there is no corresponding
window whose name I can peruse. Also, the file chosen by the user can be in an arbitrary location.

Thanks.

Bill Christens-Barry
Reply | Threaded
Open this post in threaded view
|

Re: how to get name of arbitrary file selected by user in macro?

Wayne Rasband
In ImageJ 1.38q, which is now available, the File.name and
File.directory macro functions return the name and directory path of
the last file opened using open(), saveAs(), File.open() or
File.openAsString(). Here is an example:

     str = File.openAsString("");
     print("Name: "+File.name);
     print("Directory: "+File.directory);

-wayne

On Apr 25, 2007, at 12:28 PM, Bill Christens-Barry wrote:

> How can I get the name and path of a text file opened by the user in a
> macro?
> The macro opens the file this way:
>
> f = File.openAsString("");
>
> After looking at the list archives and online doc, I haven't figured
> out how to
> get at the name or path when they are not already known. Note that I am
> opening a text file and there is no corresponding window whose name I
> can
> peruse. Also, the file chosen by the user can be in an arbitrary
> location.
>
> Thanks.
>
> Bill Christens-Barry
>