Use the CHKDLO command. Enter the name of the document or file in the DLO parameter, and the path of the folder in the FLR parameter. For a folder within a folder, it is entered like a path:
CHKDLO DLO(DOCNAME) FLR(‘FLDRLVL1/FLDRLVL2′) OBJTYPE(*DOC)
Inside of a CL program, you would monitor for the CPF8A82 message, which will indicate that the file or document doesn’t exist.
Note that this will only work within the QDLS file system, so as long as the the file is inside a true folder, it should be good. Outside of QDLS, you may need to find or create a utility that will do this.
As Cwc mentioned, the CHKDLO command may work for you if you’re interested in the QDLS file system. Another approach, which would work with all file sytems, would be to create your own command and utilize a system API called stat (for Get File Information). The source for the command USESTAT might be:
CMD PROMPT(‘Check File Existence’)
PARM KWD(PATH) TYPE(*CHAR) LEN(1024) MIN(1)
and the source for the CPP USESTATCPP:
Dcl Var(&Path_In) Type(*Char) Len(1024)
Dcl Var(&Path_Used) Type(*Char) Len(1025)
Dcl Var(&RtnCde) Type(*Int)
Dcl Var(&Results) Type(*Char) Len(128)
Dcl Var(&Null) Type(*Char) Len(1) Value(x’00′)
ChgVar Var(&Path_Used) Value(&Path_In *TCat &Null)
CallPrc Prc(‘stat’) Parm((&Path_Used) (&Results)) +
If Cond(&RtnCde = 0) Then(SndPgmMsg Msg(‘File +
was found’) ToPgmQ(*Ext))
CallPrc Prc(‘perror’) Parm((*Omit))
Compiling the CL source with:
CRTPGM PGM(USESTATCPP) BNDDIR(QC2LE)
and the command with:
CRTCMD CMD(USESTAT) PGM(USESTATCPP)
will give you a command which supports path lengths up to 1024 bytes and allows you to determine if a file is available. The stat API returns a 0 value if information was retrieved about the file (that is, the file was found) and, if the file could not be accessed for some reason, a non-zero value (specifically -1 but that’s not really important). The above program send the message “File was found’ when the file was found and you could replace this with whatever processing you want to do. The above program, if the file cannot be accessed, also sends a mesage (through an API known as ‘perror’) giving you more information on why the file was not available. The most common message would be ‘No such path or directory’ — that is, file not found You could replace this logic with whatever processing you want to do.
One warning — while both CHKDLO and the USESTAT commands will tell you if the file exists, neither tell you if the file is “full”. So if some other program is loading data into the file you will be able to “see” the file, but these two approaches (in and of themselves) do not tell you directly that all data has been loaded. This may or may not be important to you. If it is important, there are other APIs that can be used to get an exclusive lock on the file. And if you can get an exclusive lock then you can feel more confident that data loading has completed.
And a second warning that only applies to USESTAT. USESTAT doesn’t care what type of file it finds. If you have a path ‘/a/b/c/some.file’, then USESTAT ‘/a/b/c/some.file’ will return ‘File was found’. If you use USESTAT ‘/a/b/c’ you will also get ‘File was found’ as the directory c is a file from the APIs point of view. Again this may or may not be important to you.
I hope this helps,
Bruce Vining Services