Populate vectors of directory entries for the sub-directories and files in a given directory where these meet the supplied selection criteria. This function will not recurse into the sub-directories. Note that this function is essentially the same as ReadDir (hzVect<hzDirent>& Dirs, hzVect<hzDirent>& Files, const char* cpPath, const char* cpCriteria) - except that the two vectors are of strings rather than hzDirent instances.

Return TypeFunction nameArguments
hzEcodeListDir(hzVect<hzString>&,hzVect<hzString>&,const char*,const char*,)

Declared in file: hzDirectory.h
Defined in file : hzDirectory.cpp

Function Logic:

0:START 1:items items 2:unknown 3:pDir 4:pDir 5:unknown 6:Return E_OPENFAIL 7:unknown 8:unknown 9:unknown 10:unknown 11:teststr teststr teststr 12:teststr 13:unknown 14:items 15:Return E_CORRUPT 16:unknown 17:name items 18:unknown 19:name items 20:Return E_OK

Function body:

hzEcode ListDir (hzVect<hzString>& Dirs)hzVect<hzString>& Files, const char* cpPath, const char* cpCriteria, 
{
   //  Category: Directory
   //  
   //  Populate vectors of directory entries for the sub-directories and files in a given directory where these meet the supplied
   //  selection criteria. This function will not recurse into the sub-directories. Note that this function is essentially the same as
   //  ReadDir (hzVect<hzDirent>& Dirs, hzVect<hzDirent>& Files, const char* cpPath, const char* cpCriteria) - except that the two vectors
   //  are of strings rather than hzDirent instances.
   //  
   //  Arguments: 1) Dirs  The vector for the sub-directory names
   //     2) Files  The vector for the file names
   //     3) cpPath  The directory to be examined (null is taken as the current working directory)
   //     4) cpCriteria The file selection criteria (null equates to *)
   //  
   //  Returns: E_OPENFAIL If the directory cannot be opened
   //     E_CORRUPT If a directory entry could not be found by the stat function
   //     E_OK  If operation successful (even if nothing is found)
   _hzfunc("ListDir") ;
   FSTAT       fs ;            //  File status
   dirent*     pDE ;           //  Directory entry
   DIR*        pDir ;          //  Directory pointer
   hzDirent    meta ;          //  Directory entry metadata
   hzString    teststr ;       //  Test string (filenames)
   hzString    name ;          //  Directory entry name
   Dirs.Clear() ;
   Files.Clear() ;
   /*
   **  ** Move thru current directory and read files and sub directories
   **      */
   if (cpPath && cpPath[0])
       pDir = opendir(cpPath) ;
   else
       pDir = opendir(".") ;
   if (!pDir)
       return E_OPENFAIL ;
   for (; pDE = readdir(pDir) ;)
   {
       if (pDE->d_name[0]== ''.''&&(pDE->d_name[1]== 0|| (pDE->d_name[1]== ''.''&&pDE->d_name[2]== 0)))
           continue ;
       if (!FormCheckCstr(pDE->d_name, cpCriteria))
           continue ;
       if (cpPath && cpPath[0])
       {
           teststr = cpPath ;
           teststr += "/" ;
           teststr += pDE->d_name ;
       }
       else
           teststr = pDE->d_name ;
       if (stat(*teststr, &fs) == -1)
       {
           hzerr(E_CORRUPT, "Could not stat directory entry %s", *teststr) ;
           return E_CORRUPT ;
       }
       if (S_ISDIR(fs.st_mode))
       {
           name = pDE->d_name ;
           Dirs.Add(name) ;
           continue ;
       }
       if (S_ISREG(fs.st_mode))
       {
           name = pDE->d_name ;
           Files.Add(name) ;
           continue ;
       }
   }
   return E_OK ;
}