At 01:08 PM 12/14/2015, Daniele Barbieri wrote:

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


Daniele,

Here is a swift code to extract the file name using the R:BASE SLEN, SLOCP, and SGET functions.

Simply copy and paste the code below, and then run the file. Watch the presentation!

-- Start here ...
-- ExtractingFileName.RMD
-- Author: A. Razzak Memon
-- Date Created: December 14, 2015
-- Last Updated:
   -- Pre-define all variables
   SET VAR vFileWithFullPath TEXT = NULL
   SET VAR vLength INTEGER = 0
   SET VAR vLastSlash INTEGER = 0
   SET VAR vFileName TEXT = NULL
   SET VAR vFileWithFullPath = +
'C:\RIARDO_95\RIFIUTI_CLIENT\ARCHIVIO_PDF\150101-rifiuto assolutamente non pericoloso.pdf'
   -- Find the exact length
   SET VAR vLength = (SLEN(.vFileWithFullPath))
   -- Find the last slash
   SET VARIABLE vLastSlash = (SLOCP(.vFileWithFullPath,'\',-1))
   -- Now get the exact file name
SET VAR vFileName = (SGET(.vFileWithFullPath,(.vLength-.vLastSlash),(.vLastSlash+1)))
   CLS
   PAUSE 2 USING .vFileName CAPTION 'Extracting File Name' ICON WINDOWS +
   BUTTON 'Press any key to continue ...' +
   OPTION BACK_COLOR WHITE +
   |MESSAGE_FONT_NAME Tahoma +
   |MESSAGE_FONT_COLOR NAVY +
   |MESSAGE_FONT_SIZE 12
   CLEAR VARIABLES vFileWithFullPath,vLength,vLastSlash
   RETURN
-- end here

That's all there is to it!

Very Best R:egards,

Razzak.


Reply via email to