Path to string OR function(filepath)

Hi all,
It's my first post so let me know if I format incorrectly or need more information. First off, this is has been a great resource over the years. I guess I have finally gotten into igor enough I have to ask questions.

How can I:


1. Convert a symbolic path to a string,
2. Pass a path into a function, OR
3. Obtain a file path from the user using a GUI type interface as a string or in a way that can be passed to a string?


Background:


I use:
 
// Ask user where folder containing .ibw files is
String message = "Select folder containing *.ibw files to be exported"
NewPath /O/Q basepathopen
if (V_Flag)
    return -1       //user canceled
endif

*

to get a file path from the user. I then need to pass this path into a function. However, basepathopen is a path and not a string according to the debugger. Thus basepathopen is not passed in (null).

Which leads me to these questions


How can I:
1. Convert a symbolic path to a string OR
2. Pass a path into a function?

If you are curious about why I want to do this, keep reading.


I have a function (myfunction()) that works with command line inputs. However, I want to add this function to a menu so that less experienced Igor users can use it. The issue is one of the inputs is a string containing a file path e.g. "C:Users:File:". I want the user to graphically select a folder and then have igor put this string into myfunction(basepathopen).
In other words, I want some thing like this:
Function menufunction()
    // Ask user where folder containing .ibw files is
    String message = "Select folder containing *.ibw files to be exported"
    NewPath /O/Q basepathopen
    if (V_Flag)
        return -1       //user canceled
    endif
   
    myfunction(basepathopen)
end


If you've read this far, thanks. Any help is appreciated.
-Aubrey

*(Note: You may notice I say symbolic path, but then make a real folder on the disk using the /O flag if it is not already on the disk. This is intentional.)
Hi,

Curious on what you intend to to do with the basepathopen info?

Since it is a path it is available for functions that use /p=path flag, in which you would just use /p=basepathopen

Otherwise you could use pathinfo with basepathopen and get the full path string from S_path.

Andy
I think the only way to pass the symbolic path (that's our official name for the type object represented by "basepathopen") is to pass the name of it via a string input, and use the $ operator inside the function:
Function myfunction(pathname)
    String pathname

    Variable refnum
    Open/R/P=$pathname refnum
    ...
end

To get the actual file path represented by a symbolic path, use the PathInfo operation, which puts the actual path into a string called S_path.

In most cases where you need to open a file, Igor will accept the full path in a string, or a combination of /P=symbolicPath with "file name in a string".

By the way, you found the tags to get Igor-formatted code, so you're way ahead for a first-time post, and your questions are good and understandable.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
John,

Thank you so much!! I had been looking at the reply by hrodstein (see the post called Open Folder Dialog?) and had looked up the documentation for PathInfo but I think didn't realize it was that simple to access the string. Once again, this worked perfectly, thank you so much!


Andy,

I think the short answer to your question would be my function uses the basepathopen string to generate an output folder should the user not specify where to save the data. In my function, the user specifies where the data they want to import is, but an optional parameter is the output/save folder. To keep the import folder from becoming cluttered with the new files, I append "output:" to the end of the basepathopen string and use NewPath/C to create the folder if it does not exist.
So I don't think using /p flag will work for this case, but thanks because I didn't realize I could refer to symbolic paths using the /p flag. That is helpful for future reference.

More background if you are curious:

I have a function that batch open then exports .ibw files as .txt files (tab separated using Save/J) so they can be imported by other programs. We have an Atomic Force Microscope that is outputting 500+ waves for a type of calculation we want to analyse. It is important for you to know all the files are output with a format like wave0000, wave0001, wave0002 etc. Rather than graphically exporting them one wave one at a time, I give the function a string to the folder they are in, the basename of the files (e.g. wave), then the suffix of the last file to convert (e.g. 0002). It has optional arguments for a new save location, a new base name (other than wave), and a starting point other than wave 0000.

As an aside, now that I can get this path string, I should be able to do some string comparisons so that the base file name does not need to be manually entered. That way I can check for one less user mistake.


For anyone who looks back at this post:


I am now using something like this below in response to my initial post.
function myfunction()
    String basepatho, path_string
    // Ask user for folder that contains .ibw files
    String message = "Select folder containing *.ibw files to be exported"
    NewPath /O/Q basepathopen
    if (V_Flag)
        return -1       //user canceled prompt
    endif

    // **Here is the new part**
    PathInfo basepathopen  // obtain symbolic path info from "basepathopen"
    path_string = S_path  // take string (of path) generated by PathInfo and call it "path_string"
end


-Aubrey Apperson
I just perused the help entry for NewPath expecting to find that a string variable was set to the path, but this is not done.

Setting the variable to the literal path seems like a reasonable thing for this command to do.