#include <cmn_dir.h>

End of file could be use as parameter for file name filtering.
Example:
cmn_DirLst dirList("./", ".tst" ); // find all files that name finish with ".tst"
string name = dirList.GetNextName();
while (name.length() > 0) {
// TODO some operation with name
name = dirList.GetNextName();
}
Definition at line 45 of file cmn_dir.h.
Public Member Functions | |
| cmn_DirLst (const cmn_Path &a_path, const string &a_end) | |
| Default constructor. | |
| cmn_DirLst (const cmn_Path &a_path, const string &a_end, const string &a_prefix) | |
| ~cmn_DirLst () | |
| string | GetNextName () |
| this method return the name of next file that match to filter When all file are returned return empty string. | |
| string | GetNextName (ivd_GenInode_t &a_Inode) |
| this method return the name and inode of next file that match to filter When all file are returned return empty string. | |
| void | Reset () |
| Reset the search to start of directory. | |
Public Attributes | |
| log_CLASSID_m | |
Protected Attributes | |
| ivd_DirHandle_t | m_findHnd |
| Find handler. | |
Private Attributes | |
| const cmn_Path | m_path |
| The path where directory list is perform. | |
| const string | m_end |
| The file extension, for filtering. | |
| const string | m_prefix |
| the file name prefix for filtering | |
| string | m_name |
| the next name that have to be returned by GetNextName method. | |
| cmn_DirLst::cmn_DirLst | ( | const cmn_Path & | a_path, | |
| const string & | a_end | |||
| ) |
Default constructor.
Definition at line 38 of file cmn_Dir_LNX.cpp.
References log_FUNC_A_m, and Reset().
00041 : 00042 m_path(a_path), 00043 m_end(a_end), 00044 m_findHnd(NULL) 00045 { 00046 log_FUNC_A_m(cmn_DirLst, "path: " << a_path << " pfix: " << a_end); 00047 Reset(); 00048 }

| cmn_DirLst::cmn_DirLst | ( | const cmn_Path & | a_path, | |
| const string & | a_end, | |||
| const string & | a_prefix | |||
| ) |
Definition at line 52 of file cmn_Dir_LNX.cpp.
References log_FUNC_A_m, and Reset().
00056 : 00057 m_path(a_path), 00058 m_end(a_end), 00059 m_prefix(a_prefix), 00060 m_findHnd(NULL) 00061 { 00062 log_FUNC_A_m(cmn_DirLst, 00063 "path: " << a_path << " pfix: " << a_end << " prefix: " << a_prefix); 00064 Reset(); 00065 }

| cmn_DirLst::~cmn_DirLst | ( | ) |
Definition at line 69 of file cmn_Dir_LNX.cpp.
References log_ERR_m, log_FUNC_m, m_findHnd, m_path, and NULL.
00069 { 00070 log_FUNC_m(~cmn_DirLst); 00071 if (m_findHnd != NULL) { 00072 if (closedir(m_findHnd) == -1) { 00073 log_ERR_m("Can't close opendir handle: " << m_path); 00074 } 00075 } 00076 }
| string cmn_DirLst::GetNextName | ( | ) |
this method return the name of next file that match to filter When all file are returned return empty string.
Definition at line 87 of file cmn_Dir_LNX.cpp.
References cmn_EmptyCStr(), dbg_DETAIL, dirent, log_DBG_m, log_FUNC_m, m_end, m_findHnd, m_prefix, and NULL.
Referenced by fio_JourMgr::fio_JourMgr(), fsc_MedVolReader::fsc_MedVolReader(), GetPDBI(), JournalDump(), main(), bea_DiskMedium::Refresh(), fio_JourMgr::RemoveArhivedJourFile(), RemoveJournalFiles(), bea_DiskVolume::ReparseFiles(), and ShowRelFiles().
00087 { 00088 log_FUNC_m(GetNextName); 00089 if (m_findHnd == NULL) { 00090 return cmn_EmptyCStr(); 00091 } 00092 00093 struct dirent *dirp; 00094 unsigned int extLen = m_end.length(); 00095 unsigned int prefixLen = m_prefix.length(); 00096 unsigned int dirNameLen; 00097 int checkPoint; 00098 00099 while ((dirp=readdir(m_findHnd))!=NULL) { 00100 dirNameLen = strlen(dirp->d_name); 00101 checkPoint = dirNameLen - extLen; 00102 if ( (checkPoint >= 0) 00103 && (strncmp(&dirp->d_name[checkPoint], m_end.data(), extLen) == 0) 00104 && ((prefixLen == 0) 00105 || strncmp(dirp->d_name, m_prefix.data(), prefixLen) == 0)) { 00106 log_DBG_m(dbg_DETAIL, 00107 "got next name \'" << dirp->d_name << "\'."); 00108 return string(dirp->d_name); 00109 } 00110 } 00111 return cmn_EmptyCStr(); 00112 }


| string cmn_DirLst::GetNextName | ( | ivd_GenInode_t & | a_Inode | ) |
this method return the name and inode of next file that match to filter When all file are returned return empty string.
Definition at line 116 of file cmn_Dir_LNX.cpp.
References cmn_EmptyCStr(), dirent, m_end, m_findHnd, m_prefix, and NULL.
00116 { 00117 // log_FUNC_m(GetNextName); 00118 a_Inode = 0; 00119 if (m_findHnd == NULL) { 00120 return cmn_EmptyCStr(); 00121 } 00122 00123 struct dirent *dirp; 00124 unsigned int extLen = m_end.length(); 00125 unsigned int prefixLen = m_prefix.length(); 00126 unsigned int dirNameLen; 00127 int checkPoint; 00128 00129 while ((dirp=readdir(m_findHnd))!=NULL) { 00130 dirNameLen = strlen(dirp->d_name); 00131 checkPoint = dirNameLen - extLen; 00132 if ( (checkPoint >= 0) 00133 && (strncmp(&dirp->d_name[checkPoint], m_end.data(), extLen) == 0) 00134 && ((prefixLen == 0) 00135 || strncmp(dirp->d_name, m_prefix.data(), prefixLen) == 0)) { 00136 a_Inode = dirp->d_ino; 00137 return string(dirp->d_name); 00138 } 00139 } 00140 return cmn_EmptyCStr(); 00141 }

| void cmn_DirLst::Reset | ( | ) |
Reset the search to start of directory.
Definition at line 145 of file cmn_Dir_LNX.cpp.
References errno, log_FUNC_m, m_findHnd, m_path, and NULL.
Referenced by cmn_DirLst().
00145 { 00146 log_FUNC_m(Reset); 00147 if (m_findHnd != NULL) { 00148 if (closedir(m_findHnd) == -1) { 00149 throw ivd_SysError(errno, "Can't close opendir handle.", true); 00150 } 00151 } 00152 m_findHnd = opendir(m_path.c_str()); 00153 00154 if (m_findHnd == NULL) { 00155 ostringstream sstr; 00156 sstr << "Failed opendir(: " << m_path << ")"; 00157 throw ivd_SysError(errno, sstr.str(), true); 00158 } 00159 }

const cmn_Path cmn_DirLst::m_path [private] |
The path where directory list is perform.
Definition at line 64 of file cmn_dir.h.
Referenced by Reset(), and ~cmn_DirLst().
const string cmn_DirLst::m_end [private] |
The file extension, for filtering.
List of name that finish with m_end string. NOTE!
Definition at line 71 of file cmn_dir.h.
Referenced by GetNextName().
const string cmn_DirLst::m_prefix [private] |
the file name prefix for filtering
Definition at line 76 of file cmn_dir.h.
Referenced by GetNextName().
string cmn_DirLst::m_name [private] |
ivd_DirHandle_t cmn_DirLst::m_findHnd [protected] |
Find handler.
Definition at line 92 of file cmn_dir.h.
Referenced by GetNextName(), Reset(), and ~cmn_DirLst().
1.5.6