|
Is there an easy way to make a CL program step through the objects in an IFS directory?
I wrote some CL commands called OPENDIR, READDIR, REWINDDIR and CLOSEDIR that are intended for reading IFS directories from a CL program. Here's a sample of how you might use these to read all files that end in .CSV from the /home/klemscot directory of your IFS:
PGM DCL VAR(&DIR) TYPE(*CHAR) LEN(4) DCL VAR(&FILE) TYPE(*CHAR) LEN(640) DCL VAR(&DONE) TYPE(*LGL) VALUE('0') OPENDIR HANDLE(&DIR) DIR('/home/klemscot') REGEX('.*CSV$') LOOP: READDIR HANDLE(&DIR) NAME(&FILE) MONMSG MSGID(CPF0000) EXEC(CHGVAR VAR(&DONE) VALUE('1')) IF (&DONE *EQ '0') DO CPYFRMIMPF FROMSTMF(&FILE) TOFILE(MYLIB/MYFILE) RCDDLM(*CRLF) RMVLNK OBJLNK(&FILE) GOTO LOOP ENDDO CLOSEDIR HANDLE(&DIR) ENDPGMThe REGEX parameter to OPENDIR is used to subset the results by a given regular expression. (It's an optional parameter, you can omit it if you don't need that capability.)
These CL Commands are written in a mixture of ILE CL and ILE RPG, but once you've installed them, you can call them from OPM CL as well without any worries.
These tools were written as part of an article I wrote for iSeriesNetwork.com. You can read the article and download the code from the following link (requires a Professional membership in the iSeries Network):
http://www.iseriesnetwork.com/article.cfm?id=50930If you don't have a Pro membership contact me off-list and I'll send you a copy of the code if you're interested.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.