|
Hi, Interesting... If Peter's example works where mine doesn't, it would imply a bug in the API where it isn't properly returning the length of the filename! (I wonder if theres a PTF?) In any case, if you wanted to change my example to work without relying on the API to return a proper length (but still be compatable with V3R2) all you'd have to do is change this: c if d_namelen < 256 c eval Name = %subst(d_name:1:d_namelen) c movel Name dsply_me 52 c dsply_me dsply c endif to this: 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 (Sigh... I'm so jealous of things like %str and options(*string)...) Good Luck! On Fri, 16 Jun 2000, Peter Connell wrote: > Walter, > Several people have requested a solution that I developed. Perhaps it may > help. I've attached the soucrce. > Cheers, Peter > > > > -----Original Message----- > From: Walter Hesius [mailto:Walter.Hesius@Village.uunet.be] > Sent: Friday, June 16, 2000 7:53 AM > To: RPG400-L@midrange.com > Subject: Re: List of objects in the IFS > > > I've used this example, and it works fine on one machine. > Now i've used it on another machine, and i get an huge length back, > something like 3245001546. This happens with every object in the IFS. > The objects in the IFS of this machine do not use DOS rules for naming. > Any ideas? > > ----- Original Message ----- > From: Scott Klement <klemscot@klements.com> > To: 'RPG400 list' <RPG400-L@midrange.com> > Sent: Sunday, May 28, 2000 10:00 AM > Subject: Re: List of objects in the IFS > > > > Hi Bob, > > > > On Sat, 27 May 2000, Marion, Bob wrote: > > > > > I'm trying to programmatically generate a list of objects in an IFS > > > directory. I'm trying to use opendir() and readdir(), but since I am not > a > > > C programmer I was not able to understand how to define these API's > > > parameters in RPG. Could anyone give me sample PR definitions for these > > > procedures? A little guidance on how to use them will be greatly > > > appreciated also. > > > > > > TIA > > > > > > Bob Marion > > > > > > > Sure, here's an example that just uses the DSPLY op-code > > to list each object in a directory in the IFS... > > > > Have Fun! > > > > ------------------------------cut here----------------------------------- > > > > ** 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 if d_namelen < 256 > > c eval Name = %subst(d_name:1:d_namelen) > > 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 > > > > ------------------------------cut here----------------------------------- > > > > > > +--- > > | 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 > > +--- > > > > +--- > | 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 > +--- > > > >********************************************************************************************************** > Privileged / Confidential Information may be contained in this message. If >you are not the addressee indicated in this message (or responsible for >delivery of the message to such person), you may not copy or deliver this >message to anyone. In such case, you should destroy this message, and please >notify us immediately. > > Please advise immediately if you or your employer does not consent to >Internet e-mail for messages of this kind. Opinions and other information >expressed in this message are not given or endorsed by my firm or employer >unless otherwise indicated by an authorised representative independent of this >message. +--- | 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 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.