#include <gdcmDirList.h>
Public Member Functions | |
| DirList (std::string const &dirName, bool recursive=false) | |
| Constructor. | |
| ~DirList () | |
| Destructor. | |
| void | Print (std::ostream &os=std::cout) |
| Print method. | |
| std::string const & | GetDirName () const |
| Return the name of the directory. | |
| DirListType const & | GetFilenames () const |
| Return the file names. | |
Static Public Member Functions | |
| bool | IsDirectory (std::string const &dirName) |
| Tells us if file name corresponds to a Directory. | |
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 42 of file gdcmDirList.cxx. References DirName, and Explore().
|
|
|
Destructor.
Definition at line 51 of file gdcmDirList.cxx.
00052 {
00053 }
|
|
||||||||||||
|
Explore a directory with possibility of recursion return number of files read.
Definition at line 84 of file gdcmDirList.cxx. References Filenames. Referenced by DirList().
00085 {
00086 int numberOfFiles = 0;
00087 std::string fileName;
00088 std::string dirName = Util::NormalizePath(dirpath);
00089 #ifdef _MSC_VER
00090 WIN32_FIND_DATA fileData;
00091 HANDLE hFile = FindFirstFile((dirName+"*").c_str(), &fileData);
00092
00093 for(BOOL b = (hFile != INVALID_HANDLE_VALUE); b;
00094 b = FindNextFile(hFile, &fileData))
00095 {
00096 fileName = fileData.cFileName;
00097 if( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
00098 {
00099 // Need to check for . and .. to avoid infinite loop
00100 if( fileName != "." && fileName != ".." && recursive )
00101 {
00102 numberOfFiles += Explore(dirName+fileName,recursive);
00103 }
00104 }
00105 else
00106 {
00107 Filenames.push_back(dirName+fileName);
00108 numberOfFiles++;
00109 }
00110 }
00111 if (hFile != INVALID_HANDLE_VALUE) FindClose(hFile);
00112
00113 #else
00114 // Real POSIX implementation: scandir is a BSD extension only, and doesn't
00115 // work on debian for example
00116
00117 DIR* dir = opendir(dirName.c_str());
00118 if (!dir)
00119 {
00120 return 0;
00121 }
00122
00123 // According to POSIX, the dirent structure contains a field char d_name[]
00124 // of unspecified size, with at most NAME_MAX characters preceding the
00125 // terminating null character. Use of other fields will harm the porta-
00126 // bility of your programs.
00127
00128 struct stat buf;
00129 dirent *d = 0;
00130 for (d = readdir(dir); d; d = readdir(dir))
00131 {
00132 fileName = dirName + d->d_name;
00133 stat(fileName.c_str(), &buf); //really discard output ?
00134 if( S_ISREG(buf.st_mode) ) //is it a regular file?
00135 {
00136 Filenames.push_back( fileName );
00137 numberOfFiles++;
00138 }
00139 else if( S_ISDIR(buf.st_mode) ) //directory?
00140 {
00141 if( d->d_name[0] != '.' && recursive ) //we are also skipping hidden files
00142 {
00143 numberOfFiles += Explore( fileName, recursive);
00144 }
00145 }
00146 else
00147 {
00148 // we might need to do a different treament
00149 //abort();
00150 }
00151 }
00152 closedir(dir);
00153 #endif
00154
00155 return numberOfFiles;
00156 }
|
|
|
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. References gdcm::DirListType. Referenced by gdcm::DicomDir::CreateDicomDirChainedList(), and gdcm::SerieHelper::SetDirectory().
00054 { return Filenames; };
|
|
|
Tells us if file name corresponds to a Directory.
Definition at line 62 of file gdcmDirList.cxx.
00063 {
00064 #ifndef _MSC_VER
00065 struct stat buf;
00066 stat(dirName.c_str(), &buf);
00067 return S_ISDIR(buf.st_mode);
00068 #else
00069 return (GetFileAttributes(dirName.c_str()) & FILE_ATTRIBUTE_DIRECTORY) != 0;
00070 #endif
00071 }
|
|
|
Print method.
Definition at line 164 of file gdcmDirList.cxx. References Filenames.
|
|
|
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. |
1.3.6