目前可透過 FM TMP_GUI_DIRECTORY_LIST_FILES 捉取指定目錄下的 Folder List 與 File List,回傳的 Structure SDOKPATH 的 PATHNAME 為 CHAR(255) 因此可以
CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
但回傳的 FILE_TABLE 與 DIR_TABLE 只有名稱,並沒有 File Size, Last Modify Date,因此要再透過 CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES 捉取檔案的資料,只是此 Class Interface 並沒有回傳 Folder List,因此要與前面 FM 結合使用
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
SAMPLE CODE
REPORT Z_EX_GET_LOCAL_FILE LINE-SIZE 256.
"Variant for TMP_GUI_DIRECTORY_LIST_FILES
DATA: L_PATH(1024) TYPE C.
DATA: T_FILE_TABLE LIKE STANDARD TABLE OF SDOKPATH WITH HEADER LINE,
T_DIR_TABLE LIKE STANDARD TABLE OF SDOKPATH WITH HEADER LINE.
L_PATH = 'D:\TEST_FOLDER'. "change to your folder
CLEAR: T_FILE_TABLE, T_FILE_TABLE[], T_DIR_TABLE, T_DIR_TABLE[].
CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
EXPORTING
DIRECTORY = L_PATH
FILTER = '*.*'
TABLES
FILE_TABLE = T_FILE_TABLE
DIR_TABLE = T_DIR_TABLE
EXCEPTIONS
CNTL_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.
LOOP AT T_DIR_TABLE.
WRITE:/ T_DIR_TABLE-PATHNAME.
ENDLOOP.
"Get File Property
DATA: T_FILETAB TYPE TABLE OF FILE_INFO,
T_FILETAB_H TYPE TABLE OF FILE_INFO WITH HEADER LINE,
L_COUNT TYPE I.
DATA: L_PATH_METHOD TYPE STRING.
L_PATH_METHOD = L_PATH.
CLEAR: T_FILETAB[], T_FILETAB_H, T_FILETAB_H[].
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
EXPORTING
DIRECTORY = L_PATH_METHOD
FILES_ONLY = 'X'
CHANGING
FILE_TABLE = T_FILETAB
COUNT = L_COUNT.
T_FILETAB_H[] = T_FILETAB[].
LOOP AT T_FILE_TABLE.
LOOP AT T_FILETAB_H WHERE FILENAME = T_FILE_TABLE-PATHNAME
AND ISHIDDEN = 0.
WRITE:/1(30) T_FILE_TABLE-PATHNAME,
31(20) T_FILETAB_H-FILELENGTH,
52(10) T_FILETAB_H-WRITEDATE,
63(10) T_FILETAB_H-WRITETIME.
ENDLOOP.
ENDLOOP.
WRITEDATE WRITETIME 並不會有 Timezone,因此如果你是 Taiwan GMT+8 時,則時間要額外再處理
沒有留言:
張貼留言