Solved

Check for file in folder

Posted on 2006-11-06
5
672 Views
Last Modified: 2008-01-09
Hello,

I need to check for the existance of a file in a folder.  Is there a CHKOBJ type command to this?

Thanks Ahead.......
0
Comment
Question by:tcfrey
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
samic400 earned 125 total points
ID: 17884492
This is code I believe I used to do the same thing you are asking for -

Q. For objects in the QSYS.LIB system, I can use CHKOBJ to determine
command existence. What is the equivalent for items in the IFS?

A. Here are two solutions, one in RPG IV and one in CL.

(a) RPG IV program FileExists:

 * 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
 * That's all, folks
C                   move      *on           *inlr

The filename should be supplied as //dir/dir/file, so a valid call
would be:

CALL FILEEXISTS ('//etc/pmap')


(b) The ChkIfsObj command is

CMD        PROMPT('Validate an IFS Object')

PARM       KWD(OBJECT) TYPE(*PNAME) LEN(256) MIN(1) +
             EXPR(*YES) PROMPT('IFS object')

The ChkIfsObj command uses CL program ChkIfsObjC, shown below:

PGM        PARM(&PARM)

DCL        VAR(&PARM)      TYPE(*CHAR) LEN(256)
DCL        VAR(&RTNVALINT) TYPE(*CHAR) LEN(4)
DCL        VAR(&RTNVAL)    TYPE(*CHAR) LEN(2)
DCL        VAR(&PATH)      TYPE(*CHAR) LEN(100)
DCL        VAR(&NULL)      TYPE(*CHAR) LEN(1) VALUE(X'00')
DCL        VAR(&BUF)       TYPE(*CHAR) LEN(4096)

CHGVAR     VAR(&PATH) VALUE(&PARM *TCAT &NULL)

CALLPRC    PRC('stat') PARM(&PATH &BUF) +
             RTNVAL(%BIN(&RTNVALINT 1 4))

CHGVAR     VAR(&RTNVAL) VALUE(%BIN(&RTNVALINT))

IF         COND(&RTNVAL *NE '00') THEN(SNDPGMMSG +
             MSGID(CPF9897) MSGF(QCPFMSG) +
             MSGDTA('Object ' || &PARM |< ' not +
             found.') MSGTYPE(*ESCAPE))

ENDPGM

FileExists was written by Nick Roux
ChkIfsObj and ChkIfsObjC was written by David Leland
0
 
LVL 1

Author Comment

by:tcfrey
ID: 17901559

I tried to compile the CL above.  It says definition was not found for reference STAT
Is there somethins else I need to declare in the cl?

Thanks
0
 
LVL 13

Expert Comment

by:samic400
ID: 17906804
First, need to make sure that the source member is a CLLE type, not CLP.

Secondly, need to ensure that when you copy the code above that STAT is all lower case. This is probably your problem, it cannot find STAT in uppercase because it is case sensitive and can only be found as stat.

Thirdly, compile the source as CRTCLMOD

Last, CRTPGM and you should be all set.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Install CPIO 1 165
Find out which object is not saved 2 176
Automate iSeries SFTP to a remote SFTP host 3 2,343
DB2 iSeries Date comparison w/ sysibm.sysdummy1 18 81
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now