On Fri, 4 Jan 2002, Klein, Ron wrote:

> Is there a way to do this directly from an RPGLE program or is there an API
> that will return the list so that I can display it.  I looked at WRKLNK, but
> that will only get me a display on the screen or a printout and that is not
> a workable solution.

I'm pretty sure these APIs are on the as/400:

getcwd () - get current working directory
chdir () - change directory
opendir () - open directory for reading
readdir () -  read contents of a directory
closedir () - close directory after reading

Here is a short C program that demonstrates how these work:

/* This program demonstrates using C to change directories
 * and list the files in a directory
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>

/* Define this to be the directory you want to change to */
#define NEW_DIR "/tmp"

int
main ()
{
  char dir[1024];
  DIR *directory;
  struct dirent *entries;

  /* First we demonstrate how to get the current directory
   * Notice that getcwd() returns a *char and dir also contains
   * the name of the directory
   */
  printf ("pwd = %s\n", getcwd (dir, sizeof (dir)));
  printf ("dir = %s\n", dir);

  /* Change to NEW_DIR and check for errors */
  if (chdir (NEW_DIR) != 0)
    {
      printf ("Eek! cannot chdir to %s\n", NEW_DIR);
      return (-1);
    }

  /* Here we erase dir since we are going to call getcwd() again
   * to prove that chdir() worked.
   */
  bzero (dir, sizeof (dir));
  printf ("The files in %s are:\n", getcwd (dir, sizeof (dir)));

  /* Now open the directory we just changed to. */
  directory = opendir (NEW_DIR);

  /* Use a loop to print out all the files in the directory. */
  while ((entries = readdir (directory)) != NULL)
    {
      printf ("%s\n", entries->d_name);
    }

  /* Don't forget to close! */
  closedir (directory);

  /* Done */
  return (0);
}


James Rich
james@eaerich.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-2022 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.