2 //-----------------------------------------------------------------------------
3 #include "gdcmDirList.h"
9 #if defined(_MSC_VER) || defined (__CYGWIN__)
19 // Constructor / Destructor
21 * \ingroup gdcmDirList
23 * @param dirName root directory name
24 * @param recursive whether we want to explore recursively or not
26 gdcmDirList::gdcmDirList(std::string dirName,bool recursive)
30 Explore(name,recursive);
34 * \ingroup gdcmDirList
37 gdcmDirList::~gdcmDirList(void)
41 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
47 * \ingroup gdcmDirList
48 * \brief Get the directory name
49 * @return the directory name
51 std::string gdcmDirList::GetDirName(void)
56 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
63 * \ingroup gdcmDirList
64 * \brief Explore a directory with possibility of recursion
65 * @param dirName directory to explore
66 * @param recursive whether we want recursion or not
68 void gdcmDirList::Explore(std::string dirName,bool recursive)
72 NormalizePath(dirName);
73 #if defined(_MSC_VER) || (__CYGWIN__)
74 WIN32_FIND_DATA fileData;
75 HANDLE hFile=FindFirstFile((dirName+"*").c_str(),&fileData);
78 while( (hFile!=INVALID_HANDLE_VALUE) && (found) )
80 fileName=fileData.cFileName;
81 if(fileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
83 if( (fileName!=".") && (fileName!="..") && (recursive) )
84 Explore(dirName+fileName,recursive);
88 this->push_back(dirName+fileName);
91 found=FindNextFile(hFile,&fileData);
95 struct dirent **namelist;
96 int n=scandir(dirName.c_str(), &namelist, 0, alphasort);
98 for (int i= 0;i < n; i++)
100 fileName=namelist[i]->d_name;
101 if(namelist[i]->d_type==DT_DIR)
103 if( (fileName!=".") && (fileName!="..") && (recursive) )
104 Explore(dirName+fileName,recursive);
108 this->push_back(dirName+fileName);
114 //-----------------------------------------------------------------------------