]> Creatis software - gdcm.git/blobdiff - src/gdcmDirList.cxx
* src/gdcmUtil.cxx : bug fix to find the Windows MAC address. Now, there
[gdcm.git] / src / gdcmDirList.cxx
index 65c6b358355bff5f991ffdcc131fc616983dd96f..3362843a05e2a779d8007b3e8e784d1ba994b8bc 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDirList.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/14 21:52:06 $
-  Version:   $Revision: 1.33 $
+  Date:      $Date: 2005/01/14 23:51:40 $
+  Version:   $Revision: 1.38 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -53,24 +53,17 @@ DirList::~DirList()
 {
 }
 
-//-----------------------------------------------------------------------------
-// Print
-
 //-----------------------------------------------------------------------------
 // Public
+
 /**
  * \ingroup DirList
- * \brief   Get the directory name
- * @return the directory name 
+ * \brief   Print method
  */
-std::string const &DirList::GetDirName() const
-{
-   return DirName;
-}
-
 void DirList::Print(std::ostream &os)
 {
-   copy(begin(), end(), std::ostream_iterator<std::string>(os, "\n"));
+   std::copy(Filenames.begin(), Filenames.end(), 
+             std::ostream_iterator<std::string>(os, "\n"));
 }
 
 //-----------------------------------------------------------------------------
@@ -91,16 +84,16 @@ int DirList::Explore(std::string const &dirpath, bool recursive)
    std::string fileName;
    std::string dirName = Util::NormalizePath(dirpath);
 #ifdef _MSC_VER
-   WIN32_FIND_DATA fileData; 
-   HANDLE hFile=FindFirstFile((dirName+"*").c_str(),&fileData);
-   int found = true;
+   WIN32_FIND_DATA fileData;
+   HANDLE hFile = FindFirstFile((dirName+"*").c_str(), &fileData);
 
-   while( hFile != INVALID_HANDLE_VALUE && found )
+   for(BOOL b = (hFile != INVALID_HANDLE_VALUE); b;
+       b = FindNextFile(hFile,&fileData))
    {
       fileName = fileData.cFileName;
       if( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
       {
-         // Is the '.' and '..' usefull ?
+         // Need to check for . and .. to avoid infinite loop
          if( fileName != "." && fileName != ".." && recursive )
          {
             numberOfFiles += Explore(dirName+fileName,recursive);
@@ -108,12 +101,11 @@ int DirList::Explore(std::string const &dirpath, bool recursive)
       }
       else
       {
-         push_back(dirName+fileName);
+         Filenames.push_back(dirName+fileName);
          numberOfFiles++;
       }
-
-      found = FindNextFile(hFile, &fileData);
    }
+   if (hFile != INVALID_HANDLE_VALUE) FindClose(hFile);
 
 #else
   // Real POSIX implementation: scandir is a BSD extension only, and doesn't 
@@ -138,7 +130,7 @@ int DirList::Explore(std::string const &dirpath, bool recursive)
       stat(fileName.c_str(), &buf); //really discard output ?
       if( S_ISREG(buf.st_mode) )    //is it a regular file?
       {
-         push_back( fileName );
+         Filenames.push_back( fileName );
          numberOfFiles++;
       }
       else if( S_ISDIR(buf.st_mode) ) //directory?