Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I read the list of files in a folder?

Former Member
0 Kudos
554

I want to obtain the list of file in a folder. Is there a function module i can use directly?

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
398

Try this.

data: lt_filetable type filetable.
data: ls_filetable like line of lt_filetable.
data: lv_count type i.

CALL METHOD cl_gui_frontend_services=>directory_list_files
  EXPORTING
    directory                   = 'C:\'
*    filter                      = '*.*'
     files_only                  = 'X'
*    directories_only            =
  changing
    file_table                  = lt_filetable
    count                       = lv_count.

loop at lt_filetable into ls_filetable.
  write:/ ls_filetable-FILENAME.
endloop.

Regards,

Rich Heilman

3 REPLIES 3

Former Member
0 Kudos
398

check this sample

PARAMETER: p_fdir type pfeflnamel DEFAULT 'usrsapYRDSYSprofile'.
 
data:
  t_files like salfldir occurs 0 with header line.
 
*START-OF-SELECTION
START-OF-SELECTION.
 
* Retrieving the list of files in the given directory
  call function 'RZL_READ_DIR_LOCAL'
       exporting
            name     = p_fdir
       tables
            file_tbl = t_files.
 
* List of files are contained within table it_filedir
  loop at t_files.
    write: / t_files-NAME.
  endloop.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
399

Try this.

data: lt_filetable type filetable.
data: ls_filetable like line of lt_filetable.
data: lv_count type i.

CALL METHOD cl_gui_frontend_services=>directory_list_files
  EXPORTING
    directory                   = 'C:\'
*    filter                      = '*.*'
     files_only                  = 'X'
*    directories_only            =
  changing
    file_table                  = lt_filetable
    count                       = lv_count.

loop at lt_filetable into ls_filetable.
  write:/ ls_filetable-FILENAME.
endloop.

Regards,

Rich Heilman

former_member188685
Active Contributor
0 Kudos
398

you can use the class

CL_GUI_FRONETEND_SERVICES and method FILE_OPEN_DIALOG

CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

Parameter FILE_TABLE this opens a poup where you select the files.

using CTRL we can select the multiple files, those file will be stored into FILE_TABLE.

so you can use this file_table and read the files.