2006 Sep 04 3:51 PM
Hi,
I would like to know if there is a function module that can extract a filename from a fullpath with extension.
It's not really difficult to do such a form by myself but I would like to know if it already exist in SAP standard functions.
Regards,
Morgan
2006 Sep 04 3:52 PM
Hi morgan,
1. PC_SPLIT_COMPLETE_FILENAME
2. By giving the full path to the FM,
we get
a) file name (only file name)
b) also we can get the extension separately in other parameter
regards,
amit m.
Hi,
I would like to know if there is a function module that can extract a filename from a fullpath with extension.
It's not really difficult to do such a form by myself but I would like to know if it already exist in SAP standard functions.
Regards,
Morgan
2006 Sep 04 3:52 PM
Hi morgan,
1. PC_SPLIT_COMPLETE_FILENAME
2. By giving the full path to the FM,
we get
a) file name (only file name)
b) also we can get the extension separately in other parameter
regards,
amit m.
2006 Sep 04 4:20 PM
Thank you Amit but a problem remain : I got the filename but only the 12 first characters and i want the entire filename without extension, is it possible to have it using this FM?
regards,
Morgan
2006 Sep 04 5:18 PM
Hi,
Use the below method.
CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG.
DATA: V_FILENAME TYPE STRING,
IT_FILETABLE TYPE FILETABLE,
V_RC TYPE I.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
WINDOW_TITLE = 'File Open'
INITIAL_DIRECTORY = 'C:'
CHANGING
FILE_TABLE = IT_FILETABLE
RC = V_RC
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
OTHERS = 4.
IF SY-SUBRC = 0.
READ TABLE IT_FILETABLE INDEX 1 INTO V_FILENAME.
ELSE.
MESSAGE E100 WITH TEXT-011. " Error while opening the file
ENDIF.
Hope this code will help you. Don't forget to reward if it is helpful for you
Thanks,
GSK
2006 Sep 04 5:25 PM
Hi Morgan,
Plese check this method CL_GUI_FRONTEND_SERVICES->FILE_OPEN_DIALOG.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Import from a local file'
default_extension = 'DAT'
* DEFAULT_FILENAME =
initial_directory = 'C:'
* MULTISELECTION =
* WITH_ENCODING =
CHANGING
file_table = l_table
rc = l_rc
* USER_ACTION =
* FILE_ENCODING =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
others = 5.Hope this will help.
Regards,
Ferry Lianto
2006 Sep 04 6:00 PM
Hi
Try this code..
Regards,
Raj
Find the local directory
l_loc = 1.
WHILE sy-subrc EQ 0.
SEARCH p_ofile FOR '/' STARTING AT l_loc.
IF sy-fdpos GT 0.
ADD sy-fdpos TO l_loc.
l_cmd = p_ofile(l_loc).
l_lng = 60 - l_loc.
l_fil = p_ofile+l_loc(l_lng).
ELSE.
ADD 1 TO l_loc.
ENDIF.
ENDWHILE.
You will get the local directory in l_cmd. (So the remaining part of p_ofile is the file)
2006 Sep 04 6:41 PM
Hi Morgan,
Use this Function Module SO_SPLIT_FILE_AND_PATH.
REPORT ZTEST_SHAIL4 .
data: file_name type RLGRAP-FILENAME.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = 'D:\SP\kun.txt'
IMPORTING
STRIPPED_NAME = file_name
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.
message i001(zmess) with file_name.
Regards,
SP.
2006 Sep 05 3:43 AM
hi,
We can get the file name from full path by writing a few lines of code. In case of function module, there can be a limitation to the number of characters of file name.
try this code:
data: v_str(50) value 'c:/first/second/myfile.doc'.
types : begin of t_itab,
record like v_str,
end of t_itab.
data: itab type table of t_itab with header line,
v_lines type i.
start-of-selection.
split v_str at '/' into table itab.
describe table itab lines v_lines.
read table itab index v_lines.
if sy-subrc = 0.
write :/ 'File name :', itab-record.
endif.Regards,
Sailaja.
2006 Sep 05 8:13 AM
HI all,
thanks for you're help
I can't use the open file dialog cause it will display a popup and I don't want to prompt user for filename, just to extract filename without extension from a fullpathy I already have.
I will try other FM modules you gave me. Conerning the algoritm , I don't want to use it cause I alredy have one, just wanted to know if there is standard FM that do it but I thank you very much
regards,
Morgan
2015 Oct 30 1:06 PM
Hi,
the following function modules are useful:
CV120_SPLIT_PATH
CV120_SPLIT_FILE
Good luck
Reinhard
2016 Sep 16 3:10 PM
This could be done using regexp (source full path in lv_fullpath)
data: lv_root type string, lv_path type string, lv_filename type string, lv_ext type string.
" Should match both windows frontend and application server paths
find REGEX '^(.:\\|\/\/)(.+\\|.+\/)*(.+)\.(.+)' in lv_fullpath SUBMATCHES lv_root lv_path lv_filename lv_ext.
Result would be stored in corresponding variables.
For example:
lv_fullpath = 'c:\temp\test\filename.txt''
result:
| variable | data |
|---|---|
| lv_root | c:\ |
| lv_path | temp\test |
| lv_filename | filename |
| lv_ext | txt |
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |