2009 Oct 14 9:45 AM
Hi,
The only input I have is a path, and I need to read all TXT files from this directory. How can I do this ? There is no user interaction to manually select the files, so OPEN_FILE_DIALOG from CL_GUI_FRONTEND_SERVICES doesn't help.
Thanks in advance,
Avraham
2009 Oct 14 9:59 AM
Hi Avraham Kahana,
CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
pass parameter
MULTISELECTION = 'X'
so in FILE_TABLE (IFILE internal table) you will get list of files you have selected through file browser...
then read those files using the file path... one by one using table entries of IFILE TABLE...
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
WINDOW_TITLE = 'Local File for Conversion'
* default_extension =
* DEFAULT_FILENAME =
FILE_FILTER = CL_GUI_FRONTEND_SERVICES=>FILETYPE_TEXT " DAT or TXT etc
INITIAL_DIRECTORY = 'C:'
MULTISELECTION = 'X'
CHANGING
FILE_TABLE = IFILE
RC = RC
USER_ACTION = ACTION
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
OTHERS = 4
Hope it will solve your problem..
Thanks & Regards
ilesh 24x7
ilesh Nandaniya
2009 Oct 14 9:59 AM
Hi Avraham Kahana,
CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
pass parameter
MULTISELECTION = 'X'
so in FILE_TABLE (IFILE internal table) you will get list of files you have selected through file browser...
then read those files using the file path... one by one using table entries of IFILE TABLE...
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
WINDOW_TITLE = 'Local File for Conversion'
* default_extension =
* DEFAULT_FILENAME =
FILE_FILTER = CL_GUI_FRONTEND_SERVICES=>FILETYPE_TEXT " DAT or TXT etc
INITIAL_DIRECTORY = 'C:'
MULTISELECTION = 'X'
CHANGING
FILE_TABLE = IFILE
RC = RC
USER_ACTION = ACTION
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
OTHERS = 4
Hope it will solve your problem..
Thanks & Regards
ilesh 24x7
ilesh Nandaniya
2009 Oct 14 10:01 AM
you didn't read what I wrote
there is no user interaction to select the files, so this method doesn't help me.
2009 Oct 14 10:06 AM
2009 Oct 14 10:12 AM
You could use CALL METHOD cl_gui_frontend_services=>DIRECTORY_LIST_FILES to get the list of all the files in a directory and use any upload FM's to read the multiple files
2009 Oct 14 10:15 AM
Hi Avraham,
Try this way.
Thanks
Venkat.O
REPORT ztest_program.
DATA: wa_pfile TYPE file_table.
DATA: it_pfiles TYPE STANDARD TABLE OF file_table,
count TYPE i,
dir TYPE string VALUE 'C:\temp\'.
CALL METHOD cl_gui_frontend_services=>directory_list_files
EXPORTING
directory = dir
files_only = 'X'
CHANGING
file_table = it_pfiles
count = count
EXCEPTIONS
cntl_error = 1
directory_list_files_failed = 2
wrong_parameter = 3
error_no_gui = 4
not_supported_by_gui = 5
OTHERS = 6.
LOOP AT it_pfiles INTO wa_pfile.
WRITE wa_pfile.
ENDLOOP.
2009 Oct 14 10:19 AM
>
> The only input I have is a path, and I need to read all TXT files from this directory. How can I do this ? There is no user interaction to manually select the files, so OPEN_FILE_DIALOG from CL_GUI_FRONTEND_SERVICES doesn't help.
Hello Avraham,
As suggested you can use CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES.
But for selecting .TXT files only you need to add a small trick
DATA: IT_EGLIST TYPE STANDARD TABLE OF FILE_TABLE,
V_EGCNT TYPE I.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
EXPORTING
DIRECTORY = V_DIR
FILTER = '*.TXT'
FILES_ONLY = 'X'
CHANGING
FILE_TABLE = IT_EGLIST
COUNT = V_EGCNT
EXCEPTIONS
CNTL_ERROR = 1
DIRECTORY_LIST_FILES_FAILED = 2
WRONG_PARAMETER = 3
ERROR_NO_GUI = 4
NOT_SUPPORTED_BY_GUI = 5
OTHERS = 6.
IF SY-SUBRC = 0.
ENDIF.
2023 May 05 1:18 PM
2009 Oct 14 10:25 AM