Re: Getting a filename and directory path from a string in RPG?
- From: Barbara Morris <bmorris@xxxxxxxxxx>
- Date: Fri, 10 Mar 2006 20:02:46 -0500
Korto wrote:
I have a string that looks like this:
"c:\alpha\beta\files\estimate.jpg" and I'd like to separate this string
into a path ("c:\alpha\beta\files") and a filename ("estimate.jpg").
Now, without using an array, is there any conceivable way to accomplish
this? I'd like to create a module where all I have to do is pass it
the string and the module will return the directory path and the
filename in separate variables.
I don't think CHECKR will help in this case. CHECKR '\' will return the
position of the last character that is not '\', which will (usually?)
just be the last character in your string. Well, you could build a
string of all the characters except '\', and CHECKR with that, but
I think something like this would work (untested).
P splitPath b export
D splitPath pi
D string 65535a const varying
D path 65535a varying
D filename 65535a varying
/free
path = '';
for i = %len(string) downto 1;
if %subst(string : i : 1) = '\';
path = %subst(string : 1 : i - 1);
filename = %subst(string : i + 1);
leave;
endif;
endfor;
if path = '';
// \ was not found, so the entire path is just the filename
filename = string;
endif;
/end-free
.
- Follow-Ups:
- Re: Getting a filename and directory path from a string in RPG?
- From: Korto
- Re: Getting a filename and directory path from a string in RPG?
- From: Korto
- Re: Getting a filename and directory path from a string in RPG?
- From: Bradley V. Stone
- Re: Getting a filename and directory path from a string in RPG?
- From: Argo
- Re: Getting a filename and directory path from a string in RPG?
- References:
- Prev by Date: Re: Building SQL statements within CL
- Next by Date: Re: Building SQL statements within CL
- Previous by thread: Re: Getting a filename and directory path from a string in RPG?
- Next by thread: Re: Getting a filename and directory path from a string in RPG?
- Index(es):
Relevant Pages
|