Application Development and Automation 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: 
Read only

Empty folder

Former Member
0 Likes
716

How can I know if a directory is empty (without files)?

Somebody know a function? or have any idea?

Thanks a lot.

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
618

You can use this FM: TMP_GUI_DIRECTORY_LIST_FILES

Like:

  DATA: TBL_FILES LIKE SDOKPATH OCCURS 10 WITH HEADER LINE,
        TBL_DIRS LIKE SDOKPATH OCCURS 10 WITH HEADER LINE.


  CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
       EXPORTING
            DIRECTORY  = P_DIRECTORY
       TABLES
            FILE_TABLE = TBL_FILES
            DIR_TABLE  = TBL_DIRS.


describe table tbl_Files lines sy-index.
if sy-index is initial.
*  no files in the directory
endif. 

Regards,

Naimesh Patel

2 REPLIES 2
Read only

naimesh_patel
Active Contributor
0 Likes
619

You can use this FM: TMP_GUI_DIRECTORY_LIST_FILES

Like:

  DATA: TBL_FILES LIKE SDOKPATH OCCURS 10 WITH HEADER LINE,
        TBL_DIRS LIKE SDOKPATH OCCURS 10 WITH HEADER LINE.


  CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
       EXPORTING
            DIRECTORY  = P_DIRECTORY
       TABLES
            FILE_TABLE = TBL_FILES
            DIR_TABLE  = TBL_DIRS.


describe table tbl_Files lines sy-index.
if sy-index is initial.
*  no files in the directory
endif. 

Regards,

Naimesh Patel

Read only

0 Likes
618

Thanks a lot .

I decided to use a class.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
    EXPORTING
      DIRECTORY                   = 'C:HELLO'
*    FILTER                      = '*.*'
*    FILES_ONLY                  =
*    DIRECTORIES_ONLY            =
    CHANGING
      FILE_TABLE                  =  LV_FILES
      COUNT                       = SIZE
*  EXCEPTIONS
*    CNTL_ERROR                  = 1
*    DIRECTORY_LIST_FILES_FAILED = 2
*    WRONG_PARAMETER             = 3
*    ERROR_NO_GUI                = 4
*    NOT_SUPPORTED_BY_GUI        = 5
*    OTHERS                      = 6
          .
  IF SIZE IS INITIAL.
    MESSAGE 'La carpeta de entrada está vacia' TYPE 'I'.
    LEAVE PROGRAM.
  ENDIF.