IFS Get list of files in a directory in RPGLE

5 pts.
Tags:
IBM iSeries
IFS
IFS Commands
IFS Directory
RPGLE
Need to retrieve into a RPG program a list of all files in a folder on the IFS. Can this be done?

Answer Wiki

Thanks. We'll let you know when a new response is added.

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
:

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • PlexPro
    Thanks!
    40 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following