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: 

Get File Names & Creation Time of the files of a directory in App. Server

antony_paul2
Active Participant
0 Kudos

Dear all,

My requirement is to fetch all the file names of a paritucular direcory in the application server. After going through SDN i got some FM's like

1. EPS_GET_DIRECTORY_LISTING

2. EPS_GET_FILE_ATTRIBUTES

3. SUBST_GET_FILE_LIST

Here EPS_GET_DIRECTORY_LISTING looks perfect for my requirement. But while I tried to test the FM from SE37 its giving exception READ_DIRECTORY_FAILED for the required Directory. But the same FM is returning file names for the root directory.

Please look a above 2 scenario...

ie. if I give Export parameter as

DIR_NAME = '/'

FILE_MASK = '*'

The FM works fine.

But . if I give Export parameter as

DIR_NAME = '/XYZ'

FILE_MASK = '*'

The FM returns exception READ_DIRECTORY_FAILED .

But the directory /XYZ exists and there are files in it..Am I missing something with respect to the path am specifying.

Regards,

Antony

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi, see if this peace of code helps you.



CONSTANTS DAYS1980 TYPE I VALUE 3652.

DATA: DLIST LIKE EPSFILI OCCURS 0 WITH HEADER LINE, DPATH LIKE EPSF-EPSDIRNAM, MDATE LIKE SY-DATUM, MTIME LIKE SY-UZEIT, POINT_IN_TIME TYPE I.

DATA: BEGIN OF FATTR OCCURS 0, FILE_NAME LIKE EPSF-EPSFILNAM, FILE_SIZE LIKE EPSF-EPSFILSIZ, FILE_OWNER LIKE EPSF-EPSFILOWN, FILE_MODE LIKE EPSF-EPSFILMOD, FILE_TYPE LIKE EPSF-EPSFILTYP, FILE_MTIME(12), END OF FATTR.

PARAMETER P_PATH(50) TYPE C DEFAULT '/TMP' LOWER CASE.

DPATH = P_PATH.

CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'

EXPORTING
  DIR_NAME = DPATH
TABLES
  DIR_LIST = DLIST
EXCEPTIONS
  INVALID_EPS_SUBDIR = 1
  SAPGPARAM_FAILED = 2
  BUILD_DIRECTORY_FAILED = 3
  NO_AUTHORIZATION = 4
  READ_DIRECTORY_FAILED = 5
  TOO_MANY_READ_ERRORS = 6
  EMPTY_DIRECTORY_LIST = 7
  OTHERS = 8.

  IF SY-SUBRC EQ 0.
  LOOP AT DLIST.


CALL FUNCTION 'EPS_GET_FILE_ATTRIBUTES'
EXPORTING
  FILE_NAME = DLIST-NAME
  DIR_NAME = DPATH IMPORTING
  FILE_SIZE = FATTR-FILE_SIZE
  FILE_OWNER = FATTR-FILE_OWNER
  FILE_MODE = FATTR-FILE_MODE
  FILE_TYPE = FATTR-FILE_TYPE
  FILE_MTIME = FATTR-FILE_MTIME.


  FATTR-FILE_NAME = DLIST-NAME.
  APPEND FATTR.
    ENDLOOP.
  ENDIF.


  SORT FATTR BY FILE_NAME.

  LOOP AT FATTR.
  POINT_IN_TIME = FATTR-FILE_MTIME.

  CALL FUNCTION 'POINT_IN_TIME_CONVERT'
  EXPORTING
  POINT_IN_TIME = POINT_IN_TIME
  IMPORTING
  DATE = MDATE
  TIME = MTIME
  EXCEPTIONS OTHERS = 1.

  SUBTRACT DAYS1980 FROM MDATE.
  WRITE: / FATTR-FILE_NAME, FATTR-FILE_SIZE, MDATE, MTIME.
  ENDLOOP.

4 REPLIES 4

Former Member
0 Kudos

Hi, see if this peace of code helps you.



CONSTANTS DAYS1980 TYPE I VALUE 3652.

DATA: DLIST LIKE EPSFILI OCCURS 0 WITH HEADER LINE, DPATH LIKE EPSF-EPSDIRNAM, MDATE LIKE SY-DATUM, MTIME LIKE SY-UZEIT, POINT_IN_TIME TYPE I.

DATA: BEGIN OF FATTR OCCURS 0, FILE_NAME LIKE EPSF-EPSFILNAM, FILE_SIZE LIKE EPSF-EPSFILSIZ, FILE_OWNER LIKE EPSF-EPSFILOWN, FILE_MODE LIKE EPSF-EPSFILMOD, FILE_TYPE LIKE EPSF-EPSFILTYP, FILE_MTIME(12), END OF FATTR.

PARAMETER P_PATH(50) TYPE C DEFAULT '/TMP' LOWER CASE.

DPATH = P_PATH.

CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'

EXPORTING
  DIR_NAME = DPATH
TABLES
  DIR_LIST = DLIST
EXCEPTIONS
  INVALID_EPS_SUBDIR = 1
  SAPGPARAM_FAILED = 2
  BUILD_DIRECTORY_FAILED = 3
  NO_AUTHORIZATION = 4
  READ_DIRECTORY_FAILED = 5
  TOO_MANY_READ_ERRORS = 6
  EMPTY_DIRECTORY_LIST = 7
  OTHERS = 8.

  IF SY-SUBRC EQ 0.
  LOOP AT DLIST.


CALL FUNCTION 'EPS_GET_FILE_ATTRIBUTES'
EXPORTING
  FILE_NAME = DLIST-NAME
  DIR_NAME = DPATH IMPORTING
  FILE_SIZE = FATTR-FILE_SIZE
  FILE_OWNER = FATTR-FILE_OWNER
  FILE_MODE = FATTR-FILE_MODE
  FILE_TYPE = FATTR-FILE_TYPE
  FILE_MTIME = FATTR-FILE_MTIME.


  FATTR-FILE_NAME = DLIST-NAME.
  APPEND FATTR.
    ENDLOOP.
  ENDIF.


  SORT FATTR BY FILE_NAME.

  LOOP AT FATTR.
  POINT_IN_TIME = FATTR-FILE_MTIME.

  CALL FUNCTION 'POINT_IN_TIME_CONVERT'
  EXPORTING
  POINT_IN_TIME = POINT_IN_TIME
  IMPORTING
  DATE = MDATE
  TIME = MTIME
  EXCEPTIONS OTHERS = 1.

  SUBTRACT DAYS1980 FROM MDATE.
  WRITE: / FATTR-FILE_NAME, FATTR-FILE_SIZE, MDATE, MTIME.
  ENDLOOP.

Former Member
0 Kudos

Hi

try not to pass anything in filemask parameter

cheers,

etrafanob

kesavadas_thekkillath
Active Contributor
0 Kudos

link:[http://www.sapfans.com/sapfans/alex.htm]- check routine EXTRACT_REQUESTS

Example : check where used list of this Function module


CALL FUNCTION 'EPS_GET_DIRECTORY_PATH'
     EXPORTING
          EPS_SUBDIR             = PV_EPS_SUBDIR
     IMPORTING
          DIR_NAME               = LV_DIR_NAME
     EXCEPTIONS
          INVALID_EPS_SUBDIR     = 01
          SAPGPARAM_FAILED       = 02
          BUILD_DIRECTORY_FAILED = 03.


 CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
       EXPORTING
            DIR_NAME               = LV_DIR_NAME
            FILE_MASK              = SPACE
       TABLES
            DIR_LIST               = GT_FILE_LIST
       EXCEPTIONS
            INVALID_EPS_SUBDIR     = 11
            SAPGPARAM_FAILED       = 12
            BUILD_DIRECTORY_FAILED = 13
            NO_AUTHORIZATION       = 14
            READ_DIRECTORY_FAILED  = 17
            TOO_MANY_READ_ERRORS   = 22
            EMPTY_DIRECTORY_LIST   = 23.

antony_paul2
Active Participant
0 Kudos

Thanks Salil,

I think the export parameters of the function module are case sensitive. so eventhough am giving export paramter dir_name as /xyz in se37 guess its getting converted to /XYZ at the time of executuion.

Thannks once again

Antony