Which is why the ExtractFileName function in Delphi is a bit more protracted to accommodate the various possible conditions (and operating systems Win or Nix).
I suppose the function could be massaged into a stored procedure, but I believe the solutions provided so far are adequate for most eventualities. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Stephen Markson Sent: Wednesday, December 16, 2015 3:25 PM To: [email protected] Subject: [RBASE-L] - RE: extract file name from a full path A couple of notes about SET V vFileName=(SGET(.x,255,SLOCP(.x, '\',-1)+1)): 1. It works if the path is omitted; 2. If there is a drive letter and colon and no path, then the drive letter and colon are included in the returned variable. i.e. (SGET('C:fred.txt',255,SLOCP('C:fred.txt', '\',-1)+1))=C:fred.txt. Regards, Stephen Markson The Pharmacy Examining Board of Canada 416.979.2431 x251 -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Bruce Chitiea Sent: December-16-15 12:22 PM To: Stephen Markson 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>

