1 /*=========================================================================
4 Module: $RCSfile: gdcmDirList.cxx,v $
6 Date: $Date: 2004/06/20 18:08:47 $
7 Version: $Revision: 1.16 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmDirList.h"
25 #if defined(_MSC_VER) || defined (__CYGWIN__)
35 // Constructor / Destructor
37 * \ingroup gdcmDirList
39 * @param dirName root directory name
40 * @param recursive whether we want to explore recursively or not
42 gdcmDirList::gdcmDirList(std::string dirName,bool recursive)
46 Explore(name,recursive);
50 * \ingroup gdcmDirList
53 gdcmDirList::~gdcmDirList(void)
57 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
63 * \ingroup gdcmDirList
64 * \brief Get the directory name
65 * @return the directory name
67 std::string gdcmDirList::GetDirName(void)
72 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
79 * \ingroup gdcmDirList
80 * \brief Explore a directory with possibility of recursion
81 * @param dirName directory to explore
82 * @param recursive whether we want recursion or not
84 void gdcmDirList::Explore(std::string dirName,bool recursive)
88 NormalizePath(dirName);
89 #if defined(_MSC_VER) || (__CYGWIN__)
90 WIN32_FIND_DATA fileData;
91 HANDLE hFile=FindFirstFile((dirName+"*").c_str(),&fileData);
94 while( (hFile!=INVALID_HANDLE_VALUE) && (found) )
96 fileName=fileData.cFileName;
97 if(fileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
99 if( (fileName!=".") && (fileName!="..") && (recursive) )
100 Explore(dirName+fileName,recursive);
104 this->push_back(dirName+fileName);
107 found=FindNextFile(hFile,&fileData);
111 struct dirent **namelist;
112 int n=scandir(dirName.c_str(), &namelist, 0, alphasort);
114 for (int i= 0;i < n; i++)
116 fileName=namelist[i]->d_name;
117 if(namelist[i]->d_type==DT_DIR)
119 if( (fileName!=".") && (fileName!="..") && (recursive) )
120 Explore(dirName+fileName,recursive);
124 this->push_back(dirName+fileName);
130 //-----------------------------------------------------------------------------