Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Last component of a folder path
#1
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
Code:
Copy      Help
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.
#2
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
Code:
Copy      Help
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
Code:
Copy      Help
str s="S:\lev1\lev2\lev3\lev.last"
str s1=s
_s.getpath(s)
out s1.replace("" 0 _s.len)
Macro temp3
Code:
Copy      Help
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
Code:
Copy      Help
str s="S:\lev1\lev2\lev3\lev.last"
out _s.getfilename(s 1)
#3
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.


Forum Jump:


Users browsing this thread: 1 Guest(s)