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: 

validate filename and filepath

Former Member
977

I have a physical file name and file path.

Please send code or FM for the validation of corrct file path and existance of file in application server .

Thanks

6 REPLIES 6

laxmanakumar_appana
Active Contributor
0 Kudos
118

Hi,

Check this code :

data: begin of it_filedir occurs 10.

include structure salfldir.

data: end of it_filedir.

<b>validation of corrct file path</b>

  • Get Current Directory Listing for OUT Dir

call function 'RZL_READ_DIR_LOCAL'

exporting

name = p_fdir

tables

file_tbl = it_filedir.

if 'it_filedir' contains any records , that means given path is valid.

<b>existance of file in application server</b>

  • List of files are contained within table it_filedir

loop at it_filedir.

if x_file eq it_filedir-NAME.

-


file exist

endif

endloop.

check this FM : '/SAPDMC/LSM_F4_SERVER_FILE' also

Regards

Appana

*reward points for helpful answers

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
118

You could also try to simply open it, if sy-subrc <> 0, then you know the path/filename is not correct.

Regards,

Rich Heilman

Former Member
0 Kudos
118

Hi Sharadha,

I am not sure of any function modules . If you are trying to check the existence of any file in any directory this piece of code should work :

DATA FNAME(60) VALUE 'myfile'.

OPEN DATASET FNAME FOR INPUT.

IF SY-SUBRC = 0.

WRITE / 'File opened'.

.....

ELSE.

WRITE / 'File not found'.

ENDIF.

Regards,

Varun .

ferry_lianto
Active Contributor
0 Kudos
118

Hi Sharadha,

Have you looked FM <b>EPS_GET_DIRECTORY_LISTING</b> or <b>EPS_GET_DIRECTORY_PATH</b>?

Regards,

Ferry Lianto

Former Member
0 Kudos
118

Hi ,

Use the following code to check the correct file path.

CONSTANTS : C_FLNAME(100) VALUE

'abcdefghijklmnopqrstuvwxyz0123456789./ABCDEFGHIJKLMNOPQRSTUVWXYZ_'.

(P_UFILE - file path)

CONDENSE P_UFILE.

CLEAR V_STRLEN.

V_STRLEN = STRLEN( P_UFILE ).

  • Check File name should not contain spaces / special chars.

IF P_UFILE CN C_FLNAME.

  • Enter valid filename

MESSAGE E000 WITH 'Unix file should contain only'

'alphabets, numbers, ''_'' and ''.''' .

ELSEIF P_UFILE+0(V_STRLEN) CA SPACE.

  • Enter valid filename

MESSAGE E000 WITH 'Unix file should not contain any spaces'.

ENDIF.

regards,

vara

Former Member
0 Kudos
118

hi

good

try with following function module

EPS_GET_FILE_ATTRIBUTES Pass in a filename and a path, and will return attributes for the file

thanks

mrutyun