285 pts.
 Directory in AS/400
I have name of directory and folder in it. How should I check the document residing inside that particular folder inside the particular directory? Is there any such command for it? Thank You

Software/Hardware used:
ASKED: January 10, 2008  12:02 PM
UPDATED: January 10, 2008  4:45 PM

Answer Wiki:
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: <pre> CMD PROMPT('Check File Existence') PARM KWD(PATH) TYPE(*CHAR) LEN(1024) MIN(1) </pre> and the source for the CPP USESTATCPP: <pre> Pgm Parm(&Path_In) 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)) + RtnVal(&RtnCde) If Cond(&RtnCde = 0) Then(SndPgmMsg Msg('File + was found') ToPgmQ(*Ext)) Else Cmd(Do) CallPrc Prc('perror') Parm((*Omit)) CallPrc Prc('getchar') EndDo EndPgm </pre> Compiling the CL source with: <pre> CRTCLMOD MODULE(USESTATCPP) CRTPGM PGM(USESTATCPP) BNDDIR(QC2LE) </pre> and the command with: <pre> CRTCMD CMD(USESTAT) PGM(USESTATCPP) </pre> 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 Bruce Vining Services
Last Wiki Answer Submitted:  January 10, 2008  4:45 pm  by  Cwc   4,275 pts.
All Answer Wiki Contributors:  Cwc   4,275 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _