2 //-----------------------------------------------------------------------------
3 #include "gdcmDirList.h"
9 #ifdef GDCM_NO_ANSI_STRING_STREAM
11 #define ostringstream ostrstream
24 // Constructor / Destructor
26 * \ingroup gdcmDirList
28 * @param dirName root directory name
29 * @param recursive whether we want to explore recursively or not
31 gdcmDirList::gdcmDirList(std::string dirName,bool recursive)
36 Explore(name,recursive);
40 * \ingroup gdcmDirList
43 gdcmDirList::~gdcmDirList(void)
47 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
53 * \ingroup gdcmDirList
54 * \brief Get the directory name
55 * @return the directory name
57 std::string gdcmDirList::GetDirName(void)
62 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
69 * \ingroup gdcmDirList
70 * \brief Explore a directory with possibility of recursion
71 * @param dirName directory to explore
72 * @param recursive whether we want recursion or not
74 void gdcmDirList::Explore(std::string dirName,bool recursive)
78 NormalizePath(dirName);
81 WIN32_FIND_DATA fileData;
82 HANDLE hFile=FindFirstFile((dirName+"*").c_str(),&fileData);
85 while( (hFile!=INVALID_HANDLE_VALUE) && (found) )
87 fileName=fileData.cFileName;
88 if(fileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
90 if( (fileName!=".") && (fileName!="..") && (recursive) )
91 Explore(dirName+fileName,recursive);
95 this->push_back(dirName+fileName);
98 found=FindNextFile(hFile,&fileData);
102 struct dirent **namelist;
103 int n=scandir(dirName.c_str(), &namelist, 0, alphasort);
105 for (int i= 0;i < n; i++)
107 fileName=namelist[i]->d_name;
108 if(namelist[i]->d_type==DT_DIR)
110 if( (fileName!=".") && (fileName!="..") && (recursive) )
111 Explore(dirName+fileName,recursive);
115 this->push_back(dirName+fileName);
121 //-----------------------------------------------------------------------------