]> Creatis software - bbtk.git/blobdiff - packages/std/src/bbstdFilesFromDirectory.cxx
#3028 BBTK Bug New Normal - rights reading files in std
[bbtk.git] / packages / std / src / bbstdFilesFromDirectory.cxx
index 05283bcc7017b62055760b9e5a0b1e0fe9695fa5..6712c8cca4230ee8a6008098204ff4d8d099d93c 100644 (file)
@@ -188,7 +188,7 @@ int FilesFromDirectory::Explore(std::string const &dirpath, bool recursive)
   // Real POSIX implementation: scandir is a BSD extension only, and doesn't 
   // work on debian for example
 
-       DIR* dir = opendir(dirName.c_str());
+       DIR* dir = opendir( dirName.c_str() );
        if (!dir)
        {
                return 0;
@@ -269,12 +269,39 @@ void FilesFromDirectory::CleanFilenames( std::string basePath )
 {
        std::string tmpString;
        int i,ii,sizeFilenames = Filenames.size();
+       int j,sizeFileEnd = bbGetInputFileEnd().size();
 
+       int okEraseElement;
+       
+//Selecting just the files in the FileEnd List
+       if (bbGetInputFileEnd().size()!=0)
+       {
+               for (i=sizeFilenames-1; i>=0; i--)
+               {
+                       okEraseElement=0;
+                       for (j=0; j<sizeFileEnd; j++)
+                       {
+                               std::string tmp=Filenames[i].substr( (Filenames[i].length()) - (bbGetInputFileEnd()[j]).length() ) ;
+                               if (bbGetInputFileEnd()[j].compare( tmp )==0 )
+                               {
+                                       okEraseElement++;
+                               } // if FileEnd
+                       } // for j                                      
+
+                       if (okEraseElement==0) 
+                       { 
+                               Filenames.erase( Filenames.begin()+i );
+                       }
+               } // for i      
+       } // if FileEnd !=0
+
+       sizeFilenames = Filenames.size();
 
 // Cleanning paths with spaces 
        for (i=0; i<sizeFilenames; i++)
        {
                tmpString=Filenames[i];
+
                std::string::size_type  spacePosition = tmpString.find_first_of(' ');
                if (spacePosition != std::string::npos)
                {
@@ -286,6 +313,7 @@ void FilesFromDirectory::CleanFilenames( std::string basePath )
                } // if spacePosition
        }
 
+
 // Alphabetical order  
        for (i=0; i<sizeFilenames; i++)
        {
@@ -304,7 +332,6 @@ void FilesFromDirectory::CleanFilenames( std::string basePath )
        unsigned int lenghtBasePath = basePath.length();
        for (i=0; i<sizeFilenames; i++)
        {
-
                SimpleFilenames.push_back( Filenames[i].substr( lenghtBasePath ) );
        } // for i