07-11-2006 3:28 PM
Hi folks!
Anybody knows if there is a MF to extract the filename from a path...
for example, if i have a path like:
server\filename.ext
c:filename.ext
c:\>filename.txt
i want to extract the filename: 'filename.ext' (or just, 'filename')
Thank's in advance!
Xavi.
07-11-2006 3:34 PM
07-11-2006 3:30 PM
07-11-2006 3:35 PM
Please try the following code.
REPORT ZRICH_0005 .
PARAMETERS: FULLNAME TYPE RLGRAP-FILENAME .
DATA: file_name TYPE RLGRAP-FILENAME.
DATA: FILE_PATH TYPE RLGRAP-FILENAME.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
FULL_NAME = FULLNAME
IMPORTING
STRIPPED_NAME = file_name
FILE_PATH = FILE_PATH
* EXCEPTIONS
* X_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write:/ file_name
Regards
Rich Heilman
07-11-2006 3:34 PM
07-11-2016 4:47 PM
Function CH_SPLIT_FILENAME is not good!
It is not released and obsolete (it's saved in package DIMP_OBSOLETE), but more important, it can't handle base file names which contain the '.' (dot) character in them. The logic splits the filename to basename and extension at the first occurrence of a dot, which is a mistake! It should split them at the last occurrence of a dot.
For example, if I wanted to split the file 'Budget 2016.07.01.xlsx'. the result would be like this:
Base name: 'Budget 2016'
Extension: '07.01.xlsx'
Function SPLIT_FILENAME is also useless, because it does the same mistake, and even worse, it allows only up to 3 characters in the extension - which obviously can't handle the new Office files, and other files with longer extensions. It seems the only good option is to copy CH_SPLIT_FILENAME to a custom function module and fix the mistake by myself.
Edit right after posting as I checked this FM:
Rajesh Dash wrote:
You can also try the function module 'CRM_EMAIL_SPLIT_FILENAME'. This handles long UNIX filename.
This FM works perfectly as needed, and even returns the MIME-TYPE of the file. Helpful!
07-11-2006 3:36 PM
Hi Xavi,
1) Use this Function Module <b>SO_SPLIT_FILE_AND_PATH</b>
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
FULL_NAME = PATH
IMPORTING
STRIPPED_NAME = FILENAME
FILE_PATH = FILEPATH
2) if you want Attributes for a file <b>EPS_GET_FILE_ATTRIBUTES</b> --> Pass in a filename and a path, and will return attributes for the file
Thanks
Sudheer
07-11-2006 3:36 PM
Hi,
You can use the FM <b>CACS_SPLIT_PATH</b>
Import parameters Value
I_PATH C:TEST.TXT
Export parameters Value
E_PATH C:
E_FILENAME TEST.TXT
E_PSERVER X
Regards
vijay
07-11-2006 3:56 PM
Hi Xavier,
Use this Function Module.
<b>SO_SPLIT_FILE_AND_PATH</b>
Consider this code.
REPORT ztest_2 .
PARAMETERS : p_file TYPE rlgrap-filename DEFAULT '\serverfilename.ext'.
DATA : w_fname TYPE rlgrap-filename,
w_fpath TYPE rlgrap-filename.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = p_file
IMPORTING
stripped_name = w_fname
file_path = w_fpath
EXCEPTIONS
x_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
WRITE : / p_file,
w_fname,
w_fpath.
Regards,
Arun Samabrgi.
07-11-2006 4:05 PM
Hi Xavier,
Can use the function module
<b> (SO_SPLIT_FILE_AND_PATH)</b>.
Hope this will help you.
Cheers,
Anirban.
07-12-2006 8:17 AM
Thank's to all!
Finally I used the FM SPLIT_FILENAME. It's perfect, because you can also have the filename and the extension in two different variables... just perfect!
Thank's!
Xavi.
07-12-2006 9:01 AM
Hi Xavier,
You can also use the FM 'SO_SPLIT_FILE_AND_PATH' as Rich has mentioned. It also stores the path and the filename in separate variables... right?
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH' EXPORTING FULL_NAME = FULLNAME
IMPORTING
STRIPPED_NAME = file_name
FILE_PATH = FILE_PATH
EXCEPTIONS
X_ERROR = 1
OTHERS = 2 .
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ya.. For file name and extension, you need to do the mentioned FM...
Regards,
SP.
11-21-2012 5:21 PM
You can also try the function module 'CRM_EMAIL_SPLIT_FILENAME'. This handles long UNIX filename.