How to display files from a directory in RPGLE?

45 pts.
Tags:
AS/400
RPGLE
I want to get a list of excel files and displayed them a subfille but for some reason it doesn't work. Here is the RPG code:
MyDir = '/home/testdir ';

dirh = opendir(%trimr(MyDir));

if (dirh = *null);
p_errno = sys_errno();

Endif;
What am I doing wrong? Please help!
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 2  Replies

 
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.
  • ToddN2000
    Are you looking to pull these Excel files from the IFS folder?
    132,690 pointsBadges:
    report
  • bvining
    You don't provide much information, but assuming the opendir is failing to return a pointer I have to suspect your prototype.

    Here's an example that does open the directory (assuming it's there of course):

    h dftactgrp(*no)                                                  
                                                                      
    d CloseDir        pr            10i 0 extproc('closedir')         
    d  DirPtr                         *   value                       
                                                                      
    d GetErrno        pr              *   extproc('__errno')          
                                                                      
    d OpenDir         pr              *   extproc('opendir')          
    d  DirName                        *   value options(*string)      
                                                                      
    d dirh            s               *                               
    d Errno           s             10i 0 based(ErrnoPtr)             
    d ErrnoPtr        s               *                               
    d MyDir           s            512a                               
                                                                      
     /free                                                            
                                                                      
      MyDir = '/home/testdir ';                                       
      dirh = OpenDir(%trimr(MyDir));                                  
                                           
      if (dirh = *NULL);                   
          ErrnoPtr = GetErrno();           
          dsply %char(Errno);              
          *inlr = *on;                     
          return;                          
      endif;                               
                                           
      CloseDir(dirh);                      
                                           
      *inlr = *on;                         
      return;                              
                                           
     /end-free                             

    Bruce Vining

    PS -- If you're getting into the IFS APIs for the first time, you may find chapter 14 of my book APIs at Work (Second Edition) rather handy. The chapter is titled Integrated File System APIs and has a whole section on Opening, Reading, and Closing a Directory (all examples using RPGLE). As the author I do have to point out that I do receive proceeds from each sale.
    7,070 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.

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

Following

Share this item with your network: