]> Creatis software - bbtk.git/blobdiff - packages/std/src/bbstdFilesFromDirectory.cxx
#3278BBTK Feature New Normal - FindOptimalParam Box
[bbtk.git] / packages / std / src / bbstdFilesFromDirectory.cxx
index 7560fd896335b377d8a6803593fc3d2304aee2a9..7ea9ae3757a8377c3111190c362da2952e5cd19e 100644 (file)
@@ -50,9 +50,8 @@ void FilesFromDirectory::Process()
        Filenames.clear();
        SimpleFilenames.clear();
        DirName         = bbGetInputIn();
-       bool rec        = bbGetInputRecursive();
-       /*int nbFiles = */ Explore(DirName, rec);
-       CleanFilenames( bbGetInputIn() );
+       /*int nbFiles = */ Explore(DirName, bbGetInputRecursive(), bbGetInputRecursiveLevel() );
+       CleanFilenames( DirName );
        bbSetOutputOut(Filenames);   
        bbSetOutputOutSimple(SimpleFilenames);   
 }
@@ -62,6 +61,7 @@ void FilesFromDirectory::bbUserSetDefaultValues()
     bbSetInputIn(".");
     bbSetInputRecursive(false);  
     bbSetInputType(0);  
+    bbSetInputRecursiveLevel(999);  
 }
 
 void FilesFromDirectory::bbUserInitializeProcessing() 
@@ -87,7 +87,7 @@ std::string FilesFromDirectory::NormalizePath(std::string const &pathname)
    std::string name = pathname;
    int size = name.size();
 
-   if ( name[size-1] != FILESEPARATOR )
+   if (!((name[size-1]=='/')||(name[size-1]=='\\')))
    {
       name += FILESEPARATOR;
    }
@@ -103,11 +103,14 @@ std::string FilesFromDirectory::NormalizePath(std::string const &pathname)
 
 
 
-int FilesFromDirectory::Explore(std::string const &dirpath, bool recursive)
+int FilesFromDirectory::Explore(std::string const &dirpath, bool recursive, int recursiveLevel)
 {
-       int numberOfFiles               = 0;
-       std::string dirName     = NormalizePath(dirpath);
-       int tmpNumberOfFiles;
+       int             numberOfFiles           = 0;
+
+if (recursiveLevel>=0){
+
+       std::string dirName                     = NormalizePath(dirpath);
+       int             tmpNumberOfFiles;
        std::string fileName;
 #ifdef _MSC_VER
        WIN32_FIND_DATA fileData;
@@ -130,7 +133,7 @@ int FilesFromDirectory::Explore(std::string const &dirpath, bool recursive)
                        numberOfFiles++;
                        } // Type ALL_directories
 
-                       tmpNumberOfFiles        =       Explore(dirName+fileName, recursive);
+                       tmpNumberOfFiles        =       Explore(dirName+fileName, recursive,recursiveLevel-1);
                        if ((bbGetInputType()==2)&&tmpNumberOfFiles==0)
                        {
                        std::string temp = dirName+fileName;
@@ -141,6 +144,7 @@ int FilesFromDirectory::Explore(std::string const &dirpath, bool recursive)
                        numberOfFiles           =       numberOfFiles + tmpNumberOfFiles;
          } // if recursive
          if ( fileName != "." && fileName != ".." && !recursive )
+                {
                        if ((bbGetInputType()==1) || (bbGetInputType()==2))
                        {
                        std::string temp = dirName+fileName;
@@ -248,7 +252,7 @@ int FilesFromDirectory::Explore(std::string const &dirpath, bool recursive)
                                numberOfFiles++;
                                } // Type All_directories
 
-                               tmpNumberOfFiles        = Explore( fileName, recursive);
+                               tmpNumberOfFiles        = Explore( fileName, recursive, recursiveLevel-1);
                                if ((bbGetInputType()==2)&&tmpNumberOfFiles==0)
                                {
                                        Filenames.push_back(fileName);   
@@ -276,6 +280,7 @@ int FilesFromDirectory::Explore(std::string const &dirpath, bool recursive)
    }// closedir
 #endif
 
+} // if recursiveLevel 
 
        return numberOfFiles;
 }