× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: IFS Directory Files
  • From: Scott Klement <klemscot@xxxxxxxxxxxx>
  • Date: Sun, 15 Oct 2000 04:14:28 -0500 (CDT)



On Fri, 13 Oct 2000, Lewis Libman wrote:

> Is there a way to list the files in an IFS directory from within a batch job?
> With the intent to use the file names within the batch job.

Here's an example, written in RPG IV, of reading a directory in the IFS.
(This is the same example that I posted here in may, as well)

Of course, for your purposes, you'll need to do something else with the
filenames rather than just DSPLY-ing them... but I'll leave that up to
you :)

More info on this subject can be found in the UNIX-type API's manual, and
probably also in the "Who knew you could do that with RPG IV?" redbook.


     ** This is a simple test program, to demonstrate reading a directory
     **  using the IFS API with RPG IV.

      ** <<CHANGE THIS!!>>
     D PATHTOLIST      C                   CONST('/QDLS/MLHELP/')

     D**********************************************************************
     D*
     D* Directory Entry Structure (dirent)
     D*
     D* struct dirent {
     D*   char           d_reserved1[16];  /* Reserved                       */
     D*   unsigned int   d_reserved2;      /* Reserved                       */
     D*   ino_t          d_fileno;         /* The file number of the file    */
     D*   unsigned int   d_reclen;         /* Length of this directory entry
     D*                                     * in bytes                       */
     D*   int            d_reserved3;      /* Reserved                       */
     D*   char           d_reserved4[8];   /* Reserved                       */
     D*   qlg_nls_t      d_nlsinfo;        /* National Language Information
     D*                                     * about d_name                   */
     D*   unsigned int   d_namelen;        /* Length of the name, in bytes
     D*                                     * excluding NULL terminator      */
     D*   char           d_name[_QP0L_DIR_NAME]; /* Name...null terminated   */
     D*
     D* };
     D*
     D p_dirent        s               *
     D dirent          ds                  based(p_dirent)
     D   d_reserv1                   16A
     D   d_reserv2                   10U 0
     D   d_fileno                    10U 0
     D   d_reclen                    10U 0
     D   d_reserv3                   10I 0
     D   d_reserv4                    8A
     D   d_nlsinfo                   12A
     D     nls_ccsid                 10I 0 OVERLAY(d_nlsinfo:1)
     D     nls_cntry                  2A   OVERLAY(d_nlsinfo:5)
     D     nls_lang                   3A   OVERLAY(d_nlsinfo:7)
     D     nls_reserv                 3A   OVERLAY(d_nlsinfo:10)
     D   d_namelen                   10U 0
     D   d_name                     640A

     D*--------------------------------------------------------------------
     D* Open a Directory
     D*
     D* DIR *opendir(const char *dirname)
     D*
     D* NOTE: We are at V3R2, so we can't use OPTIONS(*STRING) yet :(
     D*--------------------------------------------------------------------
     D opendir         PR              *   EXTPROC('opendir')
     D  dirname                        *   VALUE

     D*--------------------------------------------------------------------
     D* Read Directory Entry
     D*
     D* struct dirent *readdir(DIR *dirp)
     D*
     D* NOTE: We are at V3R2, so we can't use OPTIONS(*STRING) yet :(
     D*--------------------------------------------------------------------
     D readdir         PR              *   EXTPROC('readdir')
     D  dirp                           *   VALUE


     D* a few local variables...
     D dh              S               *
     D PathName        S            256A
     D Name            S            256A


     C* Step1: Open up the directory.
     c                   eval      PathName= PATHTOLIST + x'00'
     C                   eval      dh = opendir(%addr(PathName))
     C                   if        dh = *NULL
     c                   eval      Msg = 'Cant open directory'
     c                   dsply                   Msg              50
     c                   eval      *INLR = *ON
     c                   Return
     c                   endif

     C* Step2: Read each entry from the directory (in a loop)
     c                   eval      p_dirent = readdir(dh)
     c                   dow       p_dirent <> *NULL

     C* FIXME: This code can only handle file/dir names under 256 bytes long
     C*         because thats the size of "Name"
     c     x'00'         scan      d_name        templen          10 0
     c                   if        templen < 256
     c                   eval      Name = %subst(d_name:1:templen)
     c                   movel     Name          dsply_me         52
     c     dsply_me      dsply
     c                   endif

     c                   eval      p_dirent = readdir(dh)
     c                   enddo

     C* Step3: End Program
     c                   dsply                   Pause             1
     c                   eval      *inlr = *On



+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.