|
Adam Lang wrote: date: Fri, 9 Jul 2004 10:33:20 -0400 from: "Adam Lang" <aalang@xxxxxxxxxxxxxxxxxxxx> subject: Check existence of a directory? I have a CL program that uses CHKDLO to determine the existence of a folder. We are changing things around to use directories. What would the equivalent command be to check for the existence of a directory? I assume we can't use wrklnk, because that will actually display the screen. Also, what would the correct msgid be? Adam Lang Systems Engineer Rutgers Casualty Insurance Company http://www.rutgersinsurance.com Adam: I had the same kind of problem and I found a (convoluted) solution that does not require a spooled file or any APIs, but it takes a bit of code (below). There are several distinct error messages from the CHKOUT CL command (check out a file - as a change management system might use). By monitoring for which message you get (or none at all) you can tell whether your directory path is a file, a directory or just does not exist. Note that if the CHKOUT is successful, you need to do a CHKIN to "release" the object checked-out. Try this: (Assume that &DIRECTORY is a *CHAR variable containing the path to the directory you wish to verify. Also assume that this routine executes a RETURN when the directory exists or has been created) CHKOUT OBJ(&DIRECTORY) /* Attempt to "ALCOBJ" the specified path */ MONMSG MSGID(CPFA0DA) EXEC(RETURN) /* If directory + already exists, just return */ MONMSG MSGID(CPFA0A9) EXEC(DO) /* If it does not + exist, then create it */ MKDIR DIR(&DIRECTORY) DTAAUT(*RWX) OBJAUT(*ALL) / If it does not exist, then create it */ RETURN ENDDO CHKIN OBJ(&DIRECTORY) /* Attempt to "DLCOBJ" the specified path */ (if you reach this point, the specified &DIRECTORY is a file or symbolic link, not a directory) Dave Schnee (dschnee@xxxxxxxxxxxxxxxxxxx) Barsa Consulting Group, LLC (914)-251-1234
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.