Return TypeFunction nameArguments
hzEcodeReadDir(hzVect<hzDirent>&,hzVect<hzDirent>&,const char*,const char*,)

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

Function Logic:

0:START 1:hzVect::Clear hzVect::Clear GetAbsPath rc 2:rc!=E_OK 3:Return hzwarn(rc,Could not obtain absolute path for (%s),cpPath) 4:lstat(*thePath,&fs)<0 5:Return E_NOTFOUND 6:!S_ISDIR(fs.st_mode) 7:Return hzwarn(E_TYPE,Given path (%s) is not a directory,cpPath) 8:opendir pDir 9:!pDir 10:Return hzwarn(E_OPENFAIL,Directory (%s) could not be opened,cpPath) 11:pDE=readdir(pDir); 12:pDE->d_name[0]=='.'&&(pDE->d_name[1]==0||(pDE->d_name[1]=='.'&&pDE->d_name[2]==0)) 13:cpCriteria 14:!FormCheckCstr(pDE->d_name,cpCriteria) 15:cpPath&&cpPath[0] 16:teststr teststr teststr 17:teststr 18:stat(*teststr,&fs)==-1 19:closedir 20:Return E_CORRUPT 21:S_ISDIR(fs.st_mode) 22:de_name hzDirent::InitStat hzVect::Add 23:S_ISREG(fs.st_mode) 24:de_name hzDirent::InitStat hzVect::Add 25:closedir 26:Return E_OK

Function body:

hzEcode ReadDir (hzVect<hzDirent>& Dirs, hzVect<hzDirent>& Files, const char* cpPath, const char* cpCriteria)
{
   _hzfunc("ReadDir(1)") ;
   FSTAT       fs ;
   dirent*     pDE ;
   DIR*        pDir ;
   hzDirent    meta ;
   hzString    thePath ;
   hzString    teststr ;
   hzString    de_name ;
   hzEcode     rc ;
   /*
   **  ** Move thru current directory and read files and sub directories
   **      */
   Dirs.Clear() ;
   Files.Clear() ;
   rc = GetAbsPath(thePath, cpPath) ;
   if (rc != E_OK)
       return hzwarn(rc, "Could not obtain absolute path for (%s)", cpPath) ;
   if (lstat(*thePath, &fs) < 0)
       return E_NOTFOUND ;
   if (!S_ISDIR(fs.st_mode))
       return hzwarn(E_TYPE, "Given path (%s) is not a directory", cpPath) ;
   pDir = opendir(*thePath) ;
   if (!pDir)
       return hzwarn(E_OPENFAIL, "Directory (%s) could not be opened", cpPath) ;
   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 (cpCriteria)
       {
           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)
       {
           closedir(pDir) ;
           hzerr(E_CORRUPT, "Could not stat directory entry %s", *teststr) ;
           return E_CORRUPT ;
       }
       if (S_ISDIR(fs.st_mode))
       {
           de_name = pDE->d_name ;
           meta.InitStat(thePath, de_name, fs) ;
           Dirs.Add(meta) ;
           continue ;
       }
       if (S_ISREG(fs.st_mode))
       {
           de_name = pDE->d_name ;
           meta.InitStat(thePath, de_name, fs) ;
           Files.Add(meta) ;
           continue ;
       }
   }
   closedir(pDir) ;
   return E_OK ;
}