X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fstd%2Fsrc%2FbbstdFilesFromDirectory.cxx;h=7560fd896335b377d8a6803593fc3d2304aee2a9;hb=8654fac291feca76ace7256d3f38e92edfb35919;hp=fc271c23591dd14977a420714323bd855561b9d4;hpb=de86b2c1152e6932fd8d846702aa5a72b81ded5c;p=bbtk.git diff --git a/packages/std/src/bbstdFilesFromDirectory.cxx b/packages/std/src/bbstdFilesFromDirectory.cxx index fc271c2..7560fd8 100644 --- a/packages/std/src/bbstdFilesFromDirectory.cxx +++ b/packages/std/src/bbstdFilesFromDirectory.cxx @@ -47,19 +47,21 @@ BBTK_BLACK_BOX_IMPLEMENTATION(FilesFromDirectory,bbtk::AtomicBlackBox); void FilesFromDirectory::Process() { - DirName = bbGetInputIn(); - bool rec = bbGetInputRecursive(); - /*int nbFiles = */ Explore(DirName, rec); - bbSetOutputOut(Filenames); - -// for (int i=0; id_name; + std::string temp = fileName; + if( stat(fileName.c_str(), &buf) != 0 ) + { + //gdcmErrorMacro( strerror(errno) ); + } // stat + if ( S_ISREG(buf.st_mode) ) //is it a regular file? + { + if ( d->d_name[0]!='.') + { + +/* + std::string::size_type spacePosition = temp.find_first_of(' '); + if (spacePosition != std::string::npos) + { + std::cout << "=========================================== File name : [" <d_name[0]!='.') && recursive ) //we also skip hidden files + { + if (bbGetInputType()==1) + { + Filenames.push_back(fileName); + numberOfFiles++; + } // Type All_directories + + tmpNumberOfFiles = Explore( fileName, recursive); + if ((bbGetInputType()==2)&&tmpNumberOfFiles==0) + { + Filenames.push_back(fileName); + numberOfFiles++; + } // Type Lsast_directories + numberOfFiles = numberOfFiles+tmpNumberOfFiles; + }// d_name && recursive + if ( (d->d_name[0]!='.') && !recursive ) { //we also skip hidden files + if ((bbGetInputType()==1) || (bbGetInputType()==2)) + { + Filenames.push_back(fileName); + numberOfFiles++; + } // Type All_directories + + }// d_name && !recursive + + } else { + //gdcmErrorMacro( "Unexpected error" ); + return -1; + } // Regular FILE + } + if( closedir(dir) != 0 ) + { + //gdcmErrorMacro( strerror(errno) ); + }// closedir +#endif + + + return numberOfFiles; +} + + +//------------------------------------------------------------------------------ +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; jFilenames[ii]) + { + tmpString=Filenames[i]; + Filenames[i]=Filenames[ii]; + Filenames[ii]=tmpString; + } // if + } // for ii + } // for i + +// Creating SimpleFilenames + unsigned int lenghtBasePath = basePath.length(); + for (i=0; id_name[0]!='.') { - std::string::size_type /* long int */ spacePosition = temp.find_first_of(' '); + std::string::size_type spacePosition = temp.find_first_of(' '); if (spacePosition != std::string::npos) { std::cout << "=========================================== File name : [" <