// FileFinder.h #ifndef FileFinder_H #define FileFinder_H // // David Adams // February 2003 // // Class to locate a file or files by name. // // Search proceeds through the current directory, its subdirectories // and then parent directories and their subdirectories. #include #include #include "dataset_util/FileDirectory.h" class FileFinder { public: // typedefs typedef FileDirectory::Name Name; typedef FileDirectory::NameList NameList; typedef FileDirectory::FileList FileList; public: // static methods // Make the class verbose. // Every searched directory and found file is displayed. static void verbose(bool stat=true); private: //data // Search directory. FileDirectory m_dir; // Maximum height of superdirectories to search. // 0 is current directory only. int m_height; // Maximum depth of subdirectories to search. // 0 is current directory only. int m_depth; // Maximum number of files to return. int m_max_files; // Directories to skip when searching for a file. NameList m_hidden_subdirs; public: // methods // Constructor. // dir = starting directory // height = maximum height to search // depth = maximum depth to search // max_files = max # files // Negative value is no limit for the last three. FileFinder(Name dir, int height=0, int depth=-1, int max_files=-1); // Return the starting directory. const FileDirectory& directory() const { return m_dir; } // Hide a subdirectory from file searches. // Agrument is anme without the prepended directory. void hide(Name name); // Return the maximum height. int height() const { return m_height; } // Return the maximum depth. int depth() const { return m_depth; } // Return the maximum # files. int max_files() const { return m_max_files; } // Return the hidden subdirectories. const NameList& hidden_subdirs() const { return m_hidden_subdirs; } // Is this a valid finder? // Directory must exist. bool is_valid() const; // Locate all instances of a file and append to an existing list. // The limit max_files is the maxnumber to be appended--not a // limit on the total size of the list. // A reference to the same list is returned. FileList& find_all(Name name, FileList& files) const; // Locate all instances of a file. FileList find_all(Name name) const; // Locate one instance of a file. Name find(Name name) const; }; // Output stream. std::ostream& operator<<(std::ostream& lhs, const FileFinder& rhs); #endif