00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * Directory iterator. Recursively uses opendir and readdir, so you don't 00006 * have to. Basically implements 'find'. 00007 * 00008 */ 00009 00010 #ifndef __WVDIRITER_H 00011 #define __WVDIRITER_H 00012 00013 #include <dirent.h> 00014 #include <sys/stat.h> 00015 #include <sys/types.h> 00016 00017 #include "wvstring.h" 00018 #include "wvlinklist.h" 00019 00020 struct WvDirEnt : public stat 00021 /***************************/ 00022 { 00023 // we already have everything from struct stat, but we also want the 00024 // fullname (dir/dir/file) and name (file), since they're useful 00025 WvString fullname; 00026 WvString name; 00027 }; 00028 00029 class WvDirIter 00030 /*************/ 00031 { 00032 private: 00033 bool recurse; 00034 00035 WvDirEnt info; 00036 00037 struct Dir { 00038 Dir( DIR * _d, WvString _dirname ) 00039 : d( _d ), dirname( _dirname ) 00040 {} 00041 ~Dir() 00042 { if( d ) closedir( d ); } 00043 00044 DIR * d; 00045 WvString dirname; 00046 }; 00047 00048 DeclareWvList( Dir ); 00049 DirList dirs; 00050 DirList::Iter dir; 00051 00052 public: 00053 WvDirIter( WvString dirname, bool _recurse=true ); 00054 ~WvDirIter(); 00055 00056 bool isok() const; 00057 void rewind(); 00058 bool next(); 00059 00060 const WvDirEnt *ptr() const { return &info; } 00061 WvIterStuff(const WvDirEnt); 00062 00063 int depth() const 00064 { return( dirs.count() ); } 00065 }; 00066 00067 #endif