01-21-2008 11:32 PM
Hi experts,
i've got the following problem.
I have a file in my program, and i've to create another file in the same directory of the first one, doesn't matter if the file is on the application server or is a local file. ' want to know how can i obtain the current directory of the first file.
Who can help me?
Thanks to all.
Ivan
01-22-2008 12:55 AM
Do something like this.....
DATA: lv_slash TYPE c value '\'.
DATA: lv_docname TYPE string value 'C:\this_directory\that_directory\test_File.xml'.
* Reverse the string
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = lv_docname
lang = sy-langu
IMPORTING
rstring = lv_docname
EXCEPTIONS
too_small = 1
OTHERS = 2.
* look for the first slash in reversed path/filename
* and trim it off.
SEARCH lv_docname FOR lv_slash.
IF sy-subrc = 0.
SHIFT lv_docname LEFT BY sy-fdpos PLACES.
ENDIF.
* reverse the string again to reveal the parent directory
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = lv_docname
lang = sy-langu
IMPORTING
rstring = lv_docname
EXCEPTIONS
too_small = 1
OTHERS = 2.
Regards.
Rich Heilman
01-22-2008 12:55 AM
Do something like this.....
DATA: lv_slash TYPE c value '\'.
DATA: lv_docname TYPE string value 'C:\this_directory\that_directory\test_File.xml'.
* Reverse the string
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = lv_docname
lang = sy-langu
IMPORTING
rstring = lv_docname
EXCEPTIONS
too_small = 1
OTHERS = 2.
* look for the first slash in reversed path/filename
* and trim it off.
SEARCH lv_docname FOR lv_slash.
IF sy-subrc = 0.
SHIFT lv_docname LEFT BY sy-fdpos PLACES.
ENDIF.
* reverse the string again to reveal the parent directory
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = lv_docname
lang = sy-langu
IMPORTING
rstring = lv_docname
EXCEPTIONS
too_small = 1
OTHERS = 2.
Regards.
Rich Heilman
01-22-2008 8:37 AM
No, sorry perhaps i've not been clear...
I want to create a file in the same directory of another file. How can i do this?
Thks to all
Ivan
01-22-2008 9:05 AM
Hi,
you can retrieve the directory of the file using this FM:
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = w_nom " logical file name
parameter_1 = w_numlot1
IMPORTING
file_name = w_fichier " full path of file
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
Regards,
Sooness
Edited by: Sooness Munogee on Jan 22, 2008 10:06 AM
01-22-2008 9:14 AM
Hi Ivano,
Check FM's
SO_SPLIT_FILE_AND_PATH
SO_FILENAME_GET_WITH_PATH
PC_SPLIT_COMPLETE_FILENAME
Thanks
Lakshman
06-09-2010 12:36 PM
01-22-2008 9:32 AM
Hi Ivano,
That will be very tricky as you will need to search the filename on your presentation layer. (in other words you will need to deploy file search in your ABAP )..
I Don't know complete scenario this is involved with, maybe you can try using DIRECTORY_SET_CURRENT when you get this filename and set the directory as your working directory and use DIRECTORY_GET_CURRENT from class CL_GUI_FRONTEND_SERVICES when finding the working directory..
Refere to other methods of CL_GUI_FRONTEND_SERVICES, it might be helpful.
Regards,
Mohaiyuddin
01-22-2008 10:25 AM