ProSHADE  0.6.5 (NOV 2018)
Protein Shape Descriptors and Symmetry Detection
ProSHADE_files.cpp
Go to the documentation of this file.
1 
22 //============================================ ProSHADE
23 #include "ProSHADE_files.h"
24 
42 bool ProSHADE_internal_files::findFiles ( std::vector <std::string>* saveFiles,
43  const char* path,
44  const char* ext )
45 {
46  //======================================== Locals
47  DIR* dir;
48  dirent* entry;
49 
50  //======================================== Open directory
51  dir = opendir ( path );
52  if ( dir == NULL ) { std::cerr << "!!! ProSHADE ERROR !!! Cannot open directory " << path << std::endl; return false; }
53 
54  while ( ( entry = readdir ( dir ) ) )
55  {
56  //==================================== Ignore entries starting with '.'
57  if ( entry->d_name[0] == '.' ) { ; }
58  else
59  {
60  if ( entry->d_type == DT_DIR )
61  {
62  //============================ Is directory - recurse
63  std::string newPath = std::string ( path ) + std::string ( entry->d_name ) + systemDirectorySeparator;
64  if ( !findFiles ( saveFiles, newPath.c_str(), ext ) )
65  {
66  std::cerr << "Directory recursion error!" << std::endl;
67  return false;
68  }
69  }
70  else
71  {
72  //============================ Is file - check and save
73  std::string fileName = std::string ( entry->d_name );
74  std::string extension = fileName.substr ( fileName.length() - std::string(ext).length(), fileName.length() - 1);
75  if ( std::strcmp ( extension.c_str(), std::string ( ext ).c_str() ) == 0 )
76  {
77  //======================== Has required extension?
78  saveFiles->push_back ( std::string ( path ) + std::string ( entry->d_name ) );
79  }
80  }
81  }
82  }
83  closedir ( dir );
84 
85  //======================================== Done
86  return true;
87 }
bool findFiles(std::vector< std::string > *saveFiles, const char *path, const char *ext)
Function to recursively search for files with given extension in the file path supplied.
This header file contains function and globals required for platform-independent file detection...