I created a command that functions similarly to the CHKOBJ command, except
for an IFS object.
The "heart" of the command is the following C code, which could also be
created in ILE RPG by correctly protyping the "access" API being used by
the C function.
/*
** CHKIFSOBJC
*
* PARAMETERS: Path to file
*
* DESCRIPTION: Check for IFS object
*
* RETURNS: Y if objects exists
* N if object does not exist
*
*/
char CHKIFSOBJC(const char* reffile) {
if( access(reffile, F_OK) != 0)
return 'N';
else
return 'Y';
}
The only problem with using any IFS API, is that adopted authority does not
work, which means the user executing the program must be authorized to the
entire path, and to the file itself, or else the function will look like
the object does not exist. I have solved this problem by front-ending the
above code with other code that temporarily changes the job user to a
profile with sufficient authority. This uses the QSYGETPH and QSYSETP
API's.
Hope this helps,
You do not specify what version of RPG.
With ILE you can do the following:
* FileExists
* Nick Roux
* 1997/10/02
*
* NOTE: Compile with DFTACTGRP(*NO)
*
* IFS API prototypes
*
* Access
*
Daccess PR 10I 0 extproc('access')
Dpathptr1 * value
Dmode1 10I 0 value
*
* IFS API Constants
*
DF_OK S 10I 0 inz(0)
*
* Some working environment for us
*
DFile_exists S 10I 0
Dpathptr S *
Dpathname S 21
DExists C 'File Exists'
DNotExists C 'File does not exist'
*
* Main{}
*
C *entry plist
C parm filename 20
* Set a character pointer to the file name string
C eval pathname = %trim(filename)+x'00'
C eval pathptr = %addr(pathname)
* Call the IFS API
C eval File_Exists = access(pathptr:F_OK)
* Did we find it?
C File_exists ifeq 0
C Exists dsply
C else
C NotExists dsply
C endif
* Thats all folks
C move *on *inlr
The filename should be supplied as //dir/dir/file, i.e.
CALL FILEEXISTS ('//etc/pmap') is a valid call.