PDA

View Full Version : Determining whether file exists



Guest.Visitor
01-01-1995, 02:00 AM
Group, I was working on a command which uses a file in the IFS. Is there a simple (like CHKOBJ) way to determine whether an IFS file exists? The only commands I found are DSPMFSINF and STATFS which will produce unnecessary output. If not I will probably try the QHFRTVAT API. Thanks, David Morris

Guest.Visitor
03-05-1999, 05:03 PM
David, If you are looking at APIs perhaps stat() from the UNIX APIs would be sufficient for your needs. One possible issue is that you need X access to the directories in the path (I believe no access is required to the file). For simplicity the Command DSPLNK with a MONMSG(CPFA0A9)will work, but you cant direct the result to an output file. I believe you need authority to the directories in the path and the object. HTH David

flensburg@novasol.dk
03-06-1999, 03:14 AM
On Friday, March 05, 1999, 06:03 PM, David Bye wrote: David, If you are looking at APIs perhaps stat() from the UNIX APIs would be sufficient for your needs. One possible issue is that you need X access to the directories in the path (I believe no access is required to the file). Here's a code example including the stat() Unix API - just in case should want to try it out: <pre> ** Create options: BNDDIR( QC2LE ) + ** ACTGRP( QILE ) D*/Define GlobalVar D EpochCET S Z Inz( Z'1970-01-01-00.00.00.000000' ) D EpochLoc S Z D aTime_Z S Z D mTime_Z S Z D cTime_Z S Z ** D CETofsHrs S 10I 0 D CETofsMin S 10I 0 D CETofsSec S 8F D CETofsSecI S 10I 0 D errnoI S 10I 0 Based( errnoP ) D errnoP S * D RC S 10I 0 D FileDsc S 10I 0 D FileNam S 50A Inz( '/QTCPTMM/MAIL') D*FileNam S 50A Inz( '/QTCPTMM/MAIL/HS101/- D* JW303328.NOT' ) D O_CREAT S 10I 0 Inz( 8 ) D O_RDWR S 10I 0 Inz( 4 ) D O_RDONLY S 10I 0 Inz( 1 ) D O_TEXTDATA S 10I 0 Inz( 16777216 ) D O_CODEPAGE S 10I 0 Inz( 8388608 ) D Oflag S 10I 0 Inz( 0 ) D Omode S 10U 0 Inz( 511 ) D cp S 10U 0 Inz( 819 ) D BufP S * Inz( %Addr( Buf )) D Buf DS D Mode_T 10U 0 D Ino_T 10U 0 D Nlink_T 5U 0 D Unknown1 2A D Uid_T 10U 0 D Gid_T 10U 0 D Off_T 10I 0 D aTime_T 10I 0 D mTime_T 10I 0 D cTime_T 10I 0 D Dev_T 10U 0 D Size_T 10U 0 D Alloc 10U 0 D ObjType 11A D Unknown2 1A D CodePage 5U 0 D Reserv 62A D Gen_Id 10U 0 Dperror PR 10I 0 ExtProc( 'perror' ) D * Value Options( *String ) ** Derrno PR * ExtProc( '__errno' ) ** Dopen PR 10I 0 ExtProc( 'open' ) D * Value Options( *String ) D 10I 0 Value D 10U 0 Value Options( *NoPass ) D 10U 0 Value Options( *NoPass ) ** Dclose PR 10I 0 ExtProc( 'close' ) D 10I 0 Value ** Dstat PR 10I 0 ExtProc( 'stat' ) D * Value Options( *String ) D * Value ** C CallB 'CEEUTCO' C Parm CETofsHrs C Parm CETofsMin C Parm CETofsSec C Parm *Omit ** C Eval CETofsSecI = %Int( CETofsSec ) C EpochCET AddDur CETofsSecI:*S EpochLoc ** ** Get File Attributes: ** C Eval Oflag = O_RDONLY ** C Eval FileDsc = open( %TrimR( FileNam ): Oflag ) C If FileDsc = -1 C Eval errnoP = errno C Eval RC = perror( %TrimR( FileNam )) C Return C EndIf ** C Eval RC = stat( %Trimr( FileNam ): Bufp ) ** C EpochLoc AddDur aTime_T:*S aTime_Z C EpochLoc AddDur cTime_T:*S cTime_Z C EpochLoc AddDur mTime_T:*S mTime_Z ** C Eval RC = close( FileDsc ) ** C Return ** </pre> Best regards, Carsten Flensburg

Guest.Visitor
03-08-1999, 08:27 AM
On Saturday, March 06, 1999, 04:14 AM, Carsten Flensburg wrote: On Friday, March 05, 1999, 06:03 PM, David Bye wrote: David, If you are looking at APIs perhaps stat() from the UNIX APIs would be sufficient for your needs. One possible issue is that you need X access to the directories in the path (I believe no access is required to the file). Here's a code example including the stat() Unix API - just in case should want to try it out:... Best regards, Carsten Flensburg David & Carsten, The stat API looks real promising. The data I am working with is created by a data warehouse product that was ported to the AS/400 from UNIX so it makes sense. It looks like it should be easier to use than QHFRTVAT. Thanks, David Morris

Guest.Visitor
03-09-1999, 09:57 AM
On Friday, March 05, 1999, 02:31 PM, David Morris wrote: Group, I was working on a command which uses a file in the IFS. Is there a simple (like CHKOBJ) way to determine whether an IFS file exists?... Thanks, David Morris Carsten & David, Thanks again for your help. Instead of stat() I ended up using the access() UNIX-type API which appears to work a lot like CHKOBJ. I never would have found this without your help. David Morris