#include <gdcmDirList.h>
Inheritance diagram for gdcm::DirList:


| Public Member Functions | |
| DirList (std::string const &dirName, bool recursive=false) | |
| Constructor. | |
| ~DirList () | |
| Destructor. | |
| void | Print (std::ostream &os=std::cout, std::string const &indent="") | 
| Print method. | |
| std::string const & | GetDirName () const | 
| Return the name of the directory. | |
| DirListType const & | GetFilenames () const | 
| Return the file names. | |
| void | SetPrintLevel (int level) | 
| Sets the print level for the Dicom Header Elements. | |
| int | GetPrintLevel () | 
| Gets the print level for the Dicom Entries. | |
| Static Public Member Functions | |
| static bool | IsDirectory (std::string const &dirName) | 
| Tells us if file name corresponds to a Directory. | |
| Protected Attributes | |
| int | PrintLevel | 
| Amount of printed details for each Dicom Entries : 0 : stands for the least detail level. | |
| Private Member Functions | |
| int | Explore (std::string const &dirName, bool recursive=false) | 
| Explore a directory with possibility of recursion return number of files read. | |
| Private Attributes | |
| DirListType | Filenames | 
| List of file names. | |
| std::string | DirName | 
| name of the root directory to explore | |
Definition at line 42 of file gdcmDirList.h.
| 
 | ||||||||||||
| Constructor. 
 
 Definition at line 45 of file gdcmDirList.cxx. References DirName, and Explore(). 
 | 
| 
 | 
| Destructor. 
 Definition at line 54 of file gdcmDirList.cxx. 
 | 
| 
 | ||||||||||||
| Explore a directory with possibility of recursion return number of files read. 
 
 Definition at line 98 of file gdcmDirList.cxx. References Filenames, gdcmErrorMacro, and gdcm::Util::NormalizePath(). Referenced by DirList(). 00099 { 00100 int numberOfFiles = 0; 00101 std::string fileName; 00102 std::string dirName = Util::NormalizePath(dirpath); 00103 #ifdef _MSC_VER 00104 WIN32_FIND_DATA fileData; 00105 //assert( dirName[dirName.size()-1] == '' ); 00106 HANDLE hFile = FindFirstFile((dirName+"*").c_str(), &fileData); 00107 00108 for(BOOL b = (hFile != INVALID_HANDLE_VALUE); b; 00109 b = FindNextFile(hFile, &fileData)) 00110 { 00111 fileName = fileData.cFileName; 00112 if ( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) 00113 { 00114 // Need to check for . and .. to avoid infinite loop 00115 if ( fileName != "." && fileName != ".." && recursive ) 00116 { 00117 numberOfFiles += Explore(dirName+fileName,recursive); 00118 } 00119 } 00120 else 00121 { 00122 Filenames.push_back(dirName+fileName); 00123 numberOfFiles++; 00124 } 00125 } 00126 DWORD dwError = GetLastError(); 00127 if (hFile != INVALID_HANDLE_VALUE) 00128 FindClose(hFile); 00129 if (dwError != ERROR_NO_MORE_FILES) 00130 { 00131 LPVOID lpMsgBuf; 00132 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| 00133 FORMAT_MESSAGE_FROM_SYSTEM| 00134 FORMAT_MESSAGE_IGNORE_INSERTS, 00135 NULL,GetLastError(), 00136 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 00137 (LPTSTR) &lpMsgBuf,0,NULL); 00138 00139 gdcmErrorMacro("FindNextFile error. Error is " << (char *)lpMsgBuf 00140 <<" for the directory : "<<dirName); 00141 return -1; 00142 } 00143 00144 #else 00145 // Real POSIX implementation: scandir is a BSD extension only, and doesn't 00146 // work on debian for example 00147 00148 DIR* dir = opendir(dirName.c_str()); 00149 if (!dir) 00150 { 00151 return 0; 00152 } 00153 00154 // According to POSIX, the dirent structure contains a field char d_name[] 00155 // of unspecified size, with at most NAME_MAX characters preceeding the 00156 // terminating null character. Use of other fields will harm the porta- 00157 // bility of your programs. 00158 00159 struct stat buf; 00160 dirent *d; 00161 for (d = readdir(dir); d; d = readdir(dir)) 00162 { 00163 fileName = dirName + d->d_name; 00164 if( stat(fileName.c_str(), &buf) != 0 ) 00165 { 00166 const char *str = strerror(errno); 00167 gdcmErrorMacro( str ); 00168 } 00169 if ( S_ISREG(buf.st_mode) ) //is it a regular file? 00170 { 00171 Filenames.push_back( fileName ); 00172 numberOfFiles++; 00173 } 00174 else if ( S_ISDIR(buf.st_mode) ) //directory? 00175 { 00176 if ( d->d_name[0] != '.' && recursive ) //we also skip hidden files 00177 { 00178 numberOfFiles += Explore( fileName, recursive); 00179 } 00180 } 00181 else 00182 { 00183 gdcmErrorMacro( "Unexpected error" ); 00184 return -1; 00185 } 00186 } 00187 if( closedir(dir) != 0 ) 00188 { 00189 const char *str = strerror(errno); 00190 gdcmErrorMacro( str ); 00191 } 00192 #endif 00193 00194 return numberOfFiles; 00195 } 
 | 
| 
 | 
| Return the name of the directory. 
 Definition at line 51 of file gdcmDirList.h. Referenced by gdcm::DicomDir::CreateDicomDirChainedList(). 00051 { return DirName; } 
 | 
| 
 | 
| Return the file names. 
 Definition at line 54 of file gdcmDirList.h. Referenced by gdcm::DicomDir::CreateDicomDirChainedList(), and gdcm::SerieHelper::SetDirectory(). 00054 { return Filenames; } 
 | 
| 
 | 
| Gets the print level for the Dicom Entries. 
 Definition at line 50 of file gdcmBase.h. 00050 { return PrintLevel; } 
 | 
| 
 | 
| Tells us if file name corresponds to a Directory. 
 
 
 Definition at line 65 of file gdcmDirList.cxx. References gdcmStaticErrorMacro. 00066 { 00067 struct stat fs; 00068 // std::cout << "dirName[dirName.size()-1] [" << dirName[dirName.size()-1] << "]" 00069 // << std::endl; 00070 //assert( dirName[dirName.size()-1] != GDCM_FILESEPARATOR ); 00071 if ( stat(dirName.c_str(), &fs) == 0 ) 00072 { 00073 #if _WIN32 00074 return ((fs.st_mode & _S_IFDIR) != 0); 00075 #else 00076 return S_ISDIR(fs.st_mode); 00077 #endif 00078 } 00079 else 00080 { 00081 const char *str = strerror(errno); 00082 gdcmStaticErrorMacro( str ); 00083 return false; 00084 } 00085 } 
 | 
| 
 | ||||||||||||
| Print method. 
 
 Reimplemented from gdcm::Base. Definition at line 203 of file gdcmDirList.cxx. References Filenames. 00204 { 00205 std::copy(Filenames.begin(), Filenames.end(), 00206 std::ostream_iterator<std::string>(os, "\n")); 00207 } 
 | 
| 
 | 
| Sets the print level for the Dicom Header Elements. 
 
 Definition at line 47 of file gdcmBase.h. Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), and gdcm::DicomDir::Print(). 00047 { PrintLevel = level; } 
 | 
| 
 | 
| name of the root directory to explore 
 Definition at line 64 of file gdcmDirList.h. Referenced by DirList(). | 
| 
 | 
| List of file names. 
 Definition at line 62 of file gdcmDirList.h. | 
| 
 | 
| Amount of printed details for each Dicom Entries : 0 : stands for the least detail level. 
 Definition at line 55 of file gdcmBase.h. Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), gdcm::DocEntry::Print(), gdcm::DictEntry::Print(), gdcm::DicomDirStudy::Print(), gdcm::DicomDirSerie::Print(), gdcm::DicomDirPatient::Print(), gdcm::DicomDirMeta::Print(), gdcm::DicomDir::Print(), and gdcm::DataEntry::Print(). | 
 1.4.4
 1.4.4