2015年3月23日 星期一

ABAP/4 : How to get file list from local computer folder

How to get file list from local computer folder

目前可透過 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 時,則時間要額外再處理


沒有留言:

張貼留言

How to install & specified python version or distreibtuion package version in google colab

在買了 RTX 3080 要來 挖礦...  嗯~是跑機器學習後,結果發現了 GOOGLE COLAB,其實之前在「GAN 對抗式生成網路」一書就有看到,但資訊人就是什麼都想自己安裝,在本機用 Anaconda + pyCharm 弄了 GPU 環境,結果有天從新竹回家發現家裡沒...