/** * @brief The file guard class to manage the FILE pointer automatically. * file_guard object can close the FILE pointer automatically when his scope is exit. */ classfile_guard { public: /** * @brief Construct a new file guard object * * @param file the pointer of the FILE object */ explicitfile_guard(FILE *file);
/** * @brief Get the FILE pointer. * * @return FILE* */ FILE *getfd()const;
private: FILE *file_; };
/** * @brief Find all files in a directory by name. * * @param dirpath the filepath of the directory to be searched * @param name the name of the file to be found, substring match is supported. * @param recursive whether to search the whole directory recursively, default is false. * If true, means search the whole directory recursively, like the 'find' command. * @return filevec the vector of file_entity, filepaths in the directory. */ filevec find_files(const filepath &dirpath, const std::string &name, bool recursive = false);
/** * @brief Find all files in a directory by extension. * * @param dirpath the filepath of the directory to be searched * @param extension the extension of the file to be found, with dot, like ".txt". * @param recursive whether to search the whole directory recursively, default is false. * If true, means search the whole directory recursively, like the 'find' command. * @return filevec the vector of file_entity, filepaths in the directory. */ filevec find_files_by_extension(const filepath &dirpath, const std::string &extension, bool recursive = false);