Dear Steven,
Yes, you are correct. Sorry about that. Your solution is a very
elegant and efficient design.
Thanks,
Jason
Jason Kramer
University Archives and Records Management
002 Pearson Hall
(302) 831 - 3127 (voice)
(302) 831 - 6903 (fax)
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Stephen Markson
Sent: Wednesday, December 16, 2015 1:56 PM
To: Kramer, Jason J <[email protected]>
Subject: [RBASE-L] - RE: extract file name from a full path
I'm not sure you're right about that, Jason.
In the referenced article, 260 is given as the default value of the variable
MAX_PATH in the Windows API. In Windows itself however, a path plus filename
can be much longer. Try it and see.
The given SGET function returns up to 255 characters starting immediately after
the last backslash. The second parameter of the SGET function is the number of
characters to "get". Since the file name cannot be more than 255 characters,
the entire file name will always be extracted by this function.
Regards,
Stephen Markson
The Pharmacy Examining Board of Canada
416.979.2431 x251
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Kramer, Jason J
Sent: December-16-15 12:56 PM
To: Stephen Markson
Subject: [RBASE-L] - RE: extract file name from a full path
Using 255 characters as the cut-off can have some unintended
consequences. Windows file paths (not names) max out at 260 characters (and
the example given was a full path including drive letter, not just a name).
See the Maximum Path Length Limitations section of
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
for full details. If you use 255 instead of 260 for the second parameter of
SGET, and you have a 255 character file name, then you will cut off the end of
the file name because the 255th character will not be the last character in the
string. The drive letter, colon, and backslash all count as characters and
will be part of the path.
As an added wrinkle, if your source of the file path is a Unicode
Windows API function, then you could conceivable receive a path of up to 32767
characters (same section of the MSDN page linked above). Admittedly, this is
unlikely, but possible in all modern versions of Windows. To fully account for
that, you could rewrite Stephen's function as:
SET V vFileName=(SGET(.x,(SLEN(.x)),SLOCP(.x, '\',-1)+1)).
Thanks,
Jason
Jason Kramer
University Archives and Records Management
002 Pearson Hall
(302) 831 - 3127 (voice)
(302) 831 - 6903 (fax)
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Bruce Chitiea
Sent: Wednesday, December 16, 2015 12:22 PM
To: Kramer, Jason J <[email protected]>
Subject: [RBASE-L] - RE: extract file name from a full path
That's ART!
Bruce
---
Bruce Chitiea
SafeSectors, Inc.
909.238.9012 mobile
On 2015-12-16 08:08, Stephen Markson wrote:
> Hello,
>
> Simplest way to do this?
>
> If x is the var with full path and filename:
>
> SET V vFileName=(SGET(.x,255,SLOCP(.x, '\',-1)+1))
>
> Windows file names can't be more than 255 characters and R:Base will
> automatically remove any trailing spaces.
>
>
> Regards,
>
> Stephen Markson
> The Pharmacy Examining Board of Canada
> 416.979.2431 x251
>
> From: [email protected] [mailto:[email protected]] On Behalf Of
> Kramer, Jason J
> Sent: December-14-15 1:33 PM
> To: Stephen Markson
> Subject: [RBASE-L] - RE: extract file name from a full path
>
> Dear Daniele,
> Assuming you are using a comma (,) as your delimiter
> and don't want to change it, then this code will get you the filename:
>
> SET VAR voripath TEXT =
> 'C:\RIARDO_95\RIFIUTI_CLIENT\ARCHIVIO_PDF\150101-rifiuto assolutamente
> non pericoloso.pdf'
> SET VAR vnewpath TEXT = (SRPL((SRPL(.voripath,',','?',0)),'\',',',0))
> -- Replace all the commas with question marks because commas are valid
> file name character and question marks are not. If you leave commas
> in the path, and you are using commas as your delimiter your substring
> count will be thrown off.
> -- Replace the back slashes with commas.
> SET VAR vsubcount INTEGER = (ITEMCNT(.vnewpath))
> -- Count the number of substring.
> SET VAR vfilename TEXT =
> (SRPL((SSUB(.vnewpath,.vsubcount)),'?',',',0))
> -- Return the last substring (which will always be the filename) after
> converting any questions marks back to commas.
> -- Please note that this returns the full file name, including the
> extension. If you don't want the extension, you will have to strip
> that out, but that is far more complex because a filename can contain
> multiple periods and extensions do not have to be only three or four
> characters.
>
> Thanks,
>
> Jason
>
> Jason Kramer
> University Archives and Records Management
> 002 Pearson Hall
> (302) 831 - 3127 (voice)
> (302) 831 - 6903 (fax)
>
> From: [email protected] [mailto:[email protected]] On Behalf Of
> Daniele Barbieri
> Sent: Monday, December 14, 2015 1:09 PM
> To: Kramer, Jason J <[email protected]>
> Subject: [RBASE-L] - extract file name from a full path
>
> Hello
> how can I extract the file name from a full path ?
> for example in the full path
> C:\RIARDO_95\RIFIUTI_CLIENT\ARCHIVIO_PDF\150101-rifiuto assolutamente
> non pericoloso.pdf I need to extract the file name 150101-rifiuto
> assolutamente non pericoloso.pdf
>
> TIA
>
> Daniele Barbieri
> B.M.B. Informatica
>
> ________________________________
> [Image removed by sender. Avast logo]<https://www.avast.com/antivirus>
>
>
> Questa e-mail รจ stata controllata per individuare virus con Avast
> antivirus.
> www.avast.com<https://www.avast.com/antivirus>