Posts: 1,058
Threads: 367
Joined: Oct 2007
I need to store in a variable the last component of a folder path. I wonder whether there exists a more efficient and/or standardized way to do it, other than that in the following code :
Macro
temp04
str s="S:\lev1\lev2\lev3\lev.last"
str s2.getpath(s)
int i=len(s2)
str s3.get(s i)
out s3
Many thanks in advance.
Posts: 133
Threads: 15
Joined: Jun 2014
The beauty of a macro program is that you can get the job done with more than one way.
Your method is pretty good though, but there are several other methods to get the same result.
Here are some of them that I can think of:
Macro
temp1
str s1 s="S:\lev1\lev2\lev3\lev.last"
ARRAY(str) a
int ntok=tok(s a -1 "\")
s1=a[ntok-1]
out s1
Macro
temp2
str s="S:\lev1\lev2\lev3\lev.last"
str s1=s
_s.getpath(s)
out s1.replace("" 0 _s.len)
Macro
temp3
str s1 s="S:\lev1\lev2\lev3\lev.last"
_s.getpath(s)
out s1.get(s _s.len)
;or
;out s1.right(s s.len-_s.len)
Last but not least:
Macro
temp4
str s="S:\lev1\lev2\lev3\lev.last"
out _s.getfilename(s 1)
Posts: 1,058
Threads: 367
Joined: Oct 2007
Thank you so much lionking for a detailed and useful response. I used in the past methods 1 & 4. I fully support your comment about the beauty of macro programs, and consequently QM itself. Best regards.