1 /*=========================================================================
4 Module: $RCSfile: gdcmDirList.cxx,v $
6 Date: $Date: 2004/06/28 09:30:58 $
7 Version: $Revision: 1.17 $
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)
87 NormalizePath(dirName);
88 #if defined(_MSC_VER) || (__CYGWIN__)
89 WIN32_FIND_DATA fileData;
90 HANDLE hFile=FindFirstFile((dirName+"*").c_str(),&fileData);
93 while( (hFile!=INVALID_HANDLE_VALUE) && (found) )
95 fileName=fileData.cFileName;
96 if(fileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
98 if( (fileName!=".") && (fileName!="..") && (recursive) )
99 Explore(dirName+fileName,recursive);
103 this->push_back(dirName+fileName);
106 found=FindNextFile(hFile,&fileData);
110 struct dirent **namelist;
111 int n=scandir(dirName.c_str(), &namelist, 0, alphasort);
113 for (int i= 0;i < n; i++)
115 fileName=namelist[i]->d_name;
116 if(namelist[i]->d_type==DT_DIR)
118 if( (fileName!=".") && (fileName!="..") && (recursive) )
119 Explore(dirName+fileName,recursive);
123 this->push_back(dirName+fileName);
129 //-----------------------------------------------------------------------------