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

FIND A FILE VIA SAP CODE

Former Member
0 Likes
670

I want to check if there is a file in a directory in my disk. Hoy can i do it with sap code ?

Is there any FM ?

For example i want to check if the following file exists :

c:\

001.bat

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
640

hi,

u can use CL_GUI_FRONTEND_SERVICES=>FILE_EXIST

call method cl_gui_frontend_services=>file_exist

exporting

file = filename

receiving

result = result .

if result = 'X'.

write:/ 'File is Exists'.

else.

write:/ 'File does not exist'.

endif.

do reward if it helps,

priya.

I want to check if there is a file in a directory in my disk. Hoy can i do it with sap code ?

Is there any FM ?

For example i want to check if the following file exists :

c:\

001.bat

4 REPLIES 4
Read only

Former Member
0 Likes
640

Hi,

Try the following fun modules:

PC_CHECK_FILENAME

PC_CHECK_FILENAME_WITH_EXT

Regards,

Anji

Read only

Former Member
0 Likes
640

Hello,

Check this:


REPORT zdirtest.
 
DATA lv_dir TYPE rsmrgstr-path VALUE '/usr/sap/trans/data'.
 
DATA: wa_files TYPE rsfillst,
it_files LIKE TABLE OF wa_files.
 
START-OF-SELECTION.
 
CALL FUNCTION 'SUBST_GET_FILE_LIST'
EXPORTING
dirname = lv_dir
filenm = '*'
TABLES
file_list = it_files
EXCEPTIONS
access_error = 1
OTHERS = 2.
 
IF sy-subrc <> 0.
WRITE /1 'Error! :-('.
ELSE.
 
LOOP AT it_files INTO wa_files.
WRITE: /1 wa_files-name,
wa_files-len.
ENDLOOP.
 
ENDIF.


If useful reward.

Vasanth

Read only

Former Member
Read only

Former Member
0 Likes
641

hi,

u can use CL_GUI_FRONTEND_SERVICES=>FILE_EXIST

call method cl_gui_frontend_services=>file_exist

exporting

file = filename

receiving

result = result .

if result = 'X'.

write:/ 'File is Exists'.

else.

write:/ 'File does not exist'.

endif.

do reward if it helps,

priya.