Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
marktaylor
Level II

Pick File Question

This is my first time posting here so I apologize if I'm posting in the wrong place. I wondered if anyone can help with the following. Is it possible to get only the file path part from the Pick File function.

 

If I write(names); I get {"/C:/Users/MT/file1.txt", "/C:/Users/MT/file1.txt"} but I would like just the path C:/Users/MT/ and to be associate that with a variable e.g. file_path = "C:/Users/MT/"

 

Thanks, Mark

 

names = Pick File(
"Select Data File",
"$DESKTOP",
{"Text Files|txt;csv", "All Files|*"},
1,
0,
"Data",
multiple
);

the  

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Pick File Question

In the Substr() function, just change the starting location to 2 and subtract one from the count.

path = Substr( names[1], 2, Contains( names[1], "/", -1 ) - 1 );
Wendy

View solution in original post

6 REPLIES 6
Highlighted

Re: Pick File Question

You could use the Pick Directory() function instead. Then use Files In Directory() function with the returned path to get the list of files.

Learn it once, use it forever!
Highlighted

Re: Pick File Question

I like the solution suggested by @markbailey best.  But here is another possibility that uses character functions to extract the file path.

path = Substr( names[1], 1, Contains( names[1], "/", -1 ) );
Wendy
Highlighted
marktaylor
Level II

Re: Pick File Question

Thanks Wendy, that works except for there's a leading slash so I get "/C:/Users/MT/" instead of "C:/Users/MT/".
I'm not sure where this leading / is coming from or how to get rid of it
Highlighted

Re: Pick File Question

In the Substr() function, just change the starting location to 2 and subtract one from the count.

path = Substr( names[1], 2, Contains( names[1], "/", -1 ) - 1 );
Wendy

View solution in original post

Highlighted
marktaylor
Level II

Re: Pick File Question

Thank you so much Wendy. That worked just great.
Highlighted
marktaylor
Level II

Re: Pick File Question

Thanks Mark. Much appreciated
Article Labels

    There are no labels assigned to this post.