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: 

GUI_GET_FILE_INFO

Former Member
0 Kudos

Hi,

I'm trying to get the filesize for a given filename. I manage to find a function call GUI_GET_FILE_INFO, however, the max filename (include path) is only 128. Is there another function that does not have this limit? Please help. Thanks.

Regards,

Norman

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

HI,

YOu can use the method

CL_GUI_FRONTEND_SERVICES=>FILE_GET_SIZE

expects the file name as a string (No limit).

Regards,

Ravi

Reward if it helps.

7 REPLIES 7

former_member181962
Active Contributor
0 Kudos

HI,

YOu can use the method

CL_GUI_FRONTEND_SERVICES=>FILE_GET_SIZE

expects the file name as a string (No limit).

Regards,

Ravi

Reward if it helps.

Former Member
0 Kudos

Hi,

You can use the method FILE_GET_SIZE of the class CL_GUI_FRONTEND_SERVICES

Eg:

CALL METHOD cl_gui_frontend_services=>file_get_size

EXPORTING

file_name = file_name

IMPORTING

FILE_SIZE = file_size

  • EXCEPTIONS

  • FILE_GET_SIZE_FAILED = 1

  • CNTL_ERROR = 2

  • ERROR_NO_GUI = 3

  • others = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Here the parameter file_name is of type string.No restiction in length is there..

I suppose your query is satisfied now..

Regards,

Sylendra.

0 Kudos

hi Tuang,

Use method <b>FILE_GET_SIZE</b> of class <b>CL_GUI_FRONTEND_SERVICES</b>

Regards,

Santosh

former_member188685
Active Contributor
0 Kudos

Hi,

You can do it with the help of class <b>CL_GUI_FRONTEND_SERVICES</b> and method <b> FILE_GET_SIZE</b>

check it.

DATA: fn    TYPE STRING,
      nSize TYPE I.

  fn = FILENAME.
 CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_GET_SIZE
    EXPORTING
      FILE_NAME           = fn
   IMPORTING
     FILE_SIZE            = nSize
   EXCEPTIONS
     FILE_GET_SIZE_FAILED = 1
     CNTL_ERROR           = 2
     ERROR_NO_GUI         = 3
     NOT_SUPPORTED_BY_GUI = 4
     others               = 5.

Regards

vijay

0 Kudos

Have tried using the method. Return me zero for the filesize. Is there anything I need to take note of?

The filename I pass over is of "C:\testing.txt".

0 Kudos

Hi Sie,

Just follow what Anjali Devi has posted.

Here is my code for your query.

data: size type i.

CALL METHOD cl_gui_frontend_services=>file_get_size

EXPORTING

file_name = 'D:\SP\wiprologo.jpg'

IMPORTING

FILE_SIZE = size

EXCEPTIONS

FILE_GET_SIZE_FAILED = 1

CNTL_ERROR = 2

ERROR_NO_GUI = 3

others = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL METHOD cl_gui_cfw=>flush( ).

WRITE: / size.

This will give you the exact size of the file.

Regards,

SP.

Former Member
0 Kudos

Hi,

Chek this sample code:

CALL METHOD cl_gui_frontend_services=>file_get_size
  EXPORTING
    file_name            = str
   IMPORTING
     file_size            = size.
 
<b>CALL METHOD  cl_gui_cfw=>flush( ).</b>
WRITE: / file(50), size.

Also chek out:

DATA: FILETAB TYPE TABLE OF FILE_INFO,
          FILEREC TYPE FILE_INFO,
          COUNT TYPE i,
          FZISE TYPE i.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
      EXPORTING
        DIRECTORY                   = '<Yourfilename>'
        FILTER                      = ''
        FILES_ONLY                  = 'X'
      CHANGING
        FILE_TABLE                  = FILETAB
        COUNT                       = COUNT
      EXCEPTIONS
        CNTL_ERROR                  = 1
        DIRECTORY_LIST_FILES_FAILED = 2
        WRONG_PARAMETER             = 3
        ERROR_NO_GUI                = 4
        others                      = 5.
 
    IF SY-SUBRC <> 0.
      RAISE CNTL_ERROR.
    ENDIF.
 
    IF COUNT = 0.
*     Does not exist
      RESULT = ABAP_FALSE.
      FSIZE  = 0.
    ELSE.
*     Does exist
      RESULT = ABAP_TRUE.
      READ FILETAB INDEX 1 INTO FILEREC.
      FSIZE = FILEREC-FILELENGTH.
    ENDIF.

Hope they help you.

Best Regards,

Anjali