5 pts.
 IFS Get list of files in a directory in RPGLE
Need to retrieve into a RPG program a list of all files in a folder on the IFS. Can this be done?

Software/Hardware used:
ASKED: March 27, 2009  8:07 PM
UPDATED: March 30, 2009  4:46 AM

Answer Wiki:
Hi, In case you are OK to use a bit of C functions within RPGLE then the following is the link to retrieve the list: http://www.scottklement.com/rpg/ifs.html If restricted to using RPGLE and CLLE then you can do it as follows - Listfile has to be created with the CRTPF command without a DDS, the length of the record depends on the maximum possible length of the filename in the IFS dir. - QSH needs to be installed. On execution of this command, which is nothing but an output redirection, the file listfile is populated with the filenames of the files in IFS. DCL VAR(&LSCOMMAND) TYPE(*CHAR) LEN(200) DCL VAR(&LIBRARY) TYPE(*CHAR) LEN(10) CHGVAR VAR(&LSCOMMAND) VALUE('LS /dir1/dir2/ > + /QSYS.LIB/' *TCAT &LIBRARY *TCAT + '.LIB/listfile.FILE/listfile.MBR') QSH CMD(&LSCOMMAND) USER FEEDBACK TO THIS TIP If you do not have QSHELL installed, then you probably do have FTP installed. Then you still can see what is in the IFS... use FTP to your local box using the reserved loopback IP address 127.0.0.1 Here's how to do it: The FTP command "DIR" will generate a file your RPG programs can read. Code: Your CL source should perform a CHGCURLIB &LIB so you know where the file will be put when generated. You then OPEN an FTP connection using FTP source. The IP address that you open is FTP RMTSYS('127.0.0.1') and your FTP source should look like: user password DIR /dir1 (DISK CLOSE QUIT You can then write an RPG program to read the disk file created in your &LIB called DIROUTPUT. This is a more portable solution and the output is great for an RPG subfile, which lets users pick which uploaded file they wish to process :
Last Wiki Answer Submitted:  March 30, 2009  4:46 am  by  Dreamz1974   515 pts.
All Answer Wiki Contributors:  Dreamz1974   515 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

Thanks!

 20 pts.