X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDirList.cxx;h=e2b6211f7aa4ec0ce944ce0f6ec62a94ed4e5f98;hb=35ee8ee8af32946514713d271177df8bb2298eb2;hp=18da29ffd4959cbab39eb60ec1ba51a4c0101f20;hpb=fc4f7706c78baf3f60474c06d871b82db221f37b;p=gdcm.git diff --git a/src/gdcmDirList.cxx b/src/gdcmDirList.cxx index 18da29ff..e2b6211f 100644 --- a/src/gdcmDirList.cxx +++ b/src/gdcmDirList.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDirList.cxx,v $ Language: C++ - Date: $Date: 2009/02/05 09:03:26 $ - Version: $Revision: 1.66 $ + Date: $Date: 2009/05/26 10:27:38 $ + Version: $Revision: 1.68 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -163,25 +163,43 @@ int DirList::Explore(std::string const &dirpath, bool recursive, bool all) //assert( dirName[dirName.size()-1] == '' ); HANDLE hFile = FindFirstFile((dirName+"*").c_str(), &fileData); - for(BOOL b = (hFile != INVALID_HANDLE_VALUE); b; + for(BOOL b = (hFile != INVALID_HANDLE_VALUE); + b; b = FindNextFile(hFile, &fileData)) { - fileName = fileData.cFileName; + fileName = dirName + fileData.cFileName; // avoid infinite loop! if ( GDCM_NAME_SPACE::Util::GetName(fileName) == "." || GDCM_NAME_SPACE::Util::GetName(fileName) == "..") continue; - if ( ( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) || !all) ) - // all : whe return ALL the names, no recursion + if (all) // meaningfull only when recursive=false { - numberOfFiles += Explore(dirName+fileName,recursive); + Filenames.push_back( fileName ); + numberOfFiles++; } else { - Filenames.push_back(dirName+fileName); - numberOfFiles++; - } + if ( !( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) //is it a regular file? + { + Filenames.push_back( fileName ); + numberOfFiles++; + + } + else if ( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) //directory? + { + if ( GDCM_NAME_SPACE::Util::GetName(fileName)[0] != '.' && recursive ) //we also skip hidden files + { + numberOfFiles += Explore( fileName, recursive); + } + } + else + { + gdcmErrorMacro( "Unexpected error" ); + return -1; + } + } } + DWORD dwError = GetLastError(); if (hFile != INVALID_HANDLE_VALUE) FindClose(hFile);