2 //-----------------------------------------------------------------------------
3 #include "gdcmDirList.h"
9 #ifdef GDCM_NO_ANSI_STRING_STREAM
11 #define ostringstream ostrstream
24 // ================= WARNING
25 // ================= DOXYGEN DOESN'T WORK FOR THIS FILE ?!?
28 // Constructor / Destructor
30 * \ingroup gdcmDirList
32 * @param dirName root directory name
33 * @param recursive whether we want to explore recursively or not
35 gdcmDirList::gdcmDirList(std::string dirName,bool recursive)
40 Explore(name,recursive);
44 * \ingroup gdcmDirList
47 gdcmDirList::~gdcmDirList(void)
51 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
57 * \ingroup gdcmDirList
58 * \brief Get the directory name
59 * @return the directory name
61 std::string gdcmDirList::GetDirName(void)
66 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
73 * \ingroup gdcmDirList
74 * \brief Explore a directory with possibility of recursion
75 * @param dirName directory to explore
76 * @param recursive whether we want recursion or not
78 void gdcmDirList::Explore(std::string dirName,bool recursive)
82 NormalizePath(dirName);
85 WIN32_FIND_DATA fileData;
86 HANDLE hFile=FindFirstFile((dirName+"*").c_str(),&fileData);
89 while( (hFile!=INVALID_HANDLE_VALUE) && (found) )
91 fileName=fileData.cFileName;
92 if(fileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
94 if( (fileName!=".") && (fileName!="..") && (recursive) )
95 Explore(dirName+fileName,recursive);
99 this->push_back(dirName+fileName);
102 found=FindNextFile(hFile,&fileData);
106 struct dirent **namelist;
107 int n=scandir(dirName.c_str(), &namelist, 0, alphasort);
109 for (int i= 0;i < n; i++)
111 fileName=namelist[i]->d_name;
112 if(namelist[i]->d_type==DT_DIR)
114 if( (fileName!=".") && (fileName!="..") && (recursive) )
115 Explore(dirName+fileName,recursive);
119 this->push_back(dirName+fileName);
125 //-----------------------------------------------------------------------------