Return Type | Function name | Arguments |
---|---|---|
hzEcode | ReadDir | (hzVect<hzDirent>&,const char*,const char*,) |
Declared in file: hzDirectory.h
Defined in file : hzDirectory.cpp
Function Logic:
Function body:
hzEcode ReadDir (hzVect<hzDirent>& entries, const char* cpPath, const char* cpCriteria) { _hzfunc("ReadDir(2)") ; FSTAT fs ; dirent* pDE ; DIR* pDir ; hzDirent meta ; hzString thePath ; hzString teststr ; hzString filename ; hzEcode rc ; entries.Clear() ; if (cpPath && cpPath[0]) { 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 hzwarn(E_NOTFOUND, "No such directory or file exists (%s)", *thePath) ; if (!S_ISDIR(fs.st_mode)) return hzwarn(E_TYPE, "Given path (%s) is not a directory", *thePath) ; pDir = opendir(*thePath) ; } else { GetCurrDir(thePath) ; pDir = opendir(".") ; } if (!pDir) return hzwarn(E_OPENFAIL, "Directory (%s) could not be opened", *thePath) ; 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 (thePath) { teststr = thePath ; 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 ; } filename = pDE->d_name ; meta.InitStat(thePath, filename, fs) ; entries.Add(meta) ; } closedir(pDir) ; return E_OK ; }