Run stat, then use a %bitand over Mode.
If Stat( Fullfilename : l_stat ) < 0;
// error
Iter;
Endif;
If %BitAnd( l_stat.st_Mode : 126976 ) = 16384;
// Mode is for a Directory
Endif;
Here is an example of recursively processing a folder structure.
Dcl-Proc FindXmlFiles;
Dcl-Pi FindXmlFiles;
CurrentPath Varchar(1024) Const;
End-pi;
Dcl-Ds l_stat Likeds( statds );
Dcl-Ds L_dir Likeds( dirent ) Based( p_dirent );
Dcl-s dir POINTER;
Dcl-s p_dirent POINTER;
Dcl-s Fullfilename Varchar(1024);
Dcl-s Filename Varchar(640);
Dir = Opendir(CurrentPath);
If dir = *Null;
Return;
Endif;
DoU p_dirent = *Null;
p_dirent = readdir(dir);
If p_dirent = *Null;
Leave;
EndIf;
Filename = %subst(L_dir.d_name:1:L_dir.d_namelen);
// fileno = L_dir.d_fileno;
If Filename ='.' Or Filename ='..';
Iter;
Endif;
Fullfilename = CurrentPath + '/' + filename;
If Stat( Fullfilename : l_stat ) < 0;
Iter;
Endif;
// Check if Mode is for a Directory
If %BitAnd( l_stat.st_Mode : 126976 ) = 16384;
FindXmlFiles( Fullfilename );
Iter;
Endif;
// STAT
If %Str(%addr(l_stat.st_objtype)) ='*STMF' And
EndsWith('.XML': Utl_ToUpper( Filename));
ParseXmlDoc( CurrentPath : Filename );
Endif;
Enddo;
Callp closedir(dir);
End-proc;
Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of mlazarus
Sent: Tuesday, April 25, 2017 7:34 PM
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
Subject: readdir - how to determine a folder?
I'm using the readdir API to read through a list if files in a folder. Is there an attribute available that will tell me if it's a sub-folder / directory?
-mark
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
http://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
http://amzn.to/2dEadiD
As an Amazon Associate we earn from qualifying purchases.