Mercurial > repos > chrisd > testing
diff gene_fraction/src/dir_util.h @ 0:f95150c37d38 draft default tip
planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
author | chrisd |
---|---|
date | Sun, 21 Feb 2016 23:31:55 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gene_fraction/src/dir_util.h Sun Feb 21 23:31:55 2016 -0500 @@ -0,0 +1,43 @@ +#ifndef DIR_UTIL_H +#define DIR_UTIL_H + +#include <list> +#include <iostream> +#include <string> +#include <dirent.h> + +/* + * Parses a directory of sam files + */ +static inline std::list<std::string> +parse_sam_dir(const std::string &directory) { + DIR *dir; + struct dirent *ent; + std::string dir_path = directory; + + dir = opendir(dir_path.c_str()); + // is dir open/valid? + if(dir == NULL) { + std::cout << "Not a valid directory" << std::endl; + exit(EXIT_FAILURE); + } + + std::list<std::string> sam_files; + std::string fn; + std::string ext; + std::string file_type = ".sam"; + + // get all files with a .sam file extension + while((ent = readdir(dir)) != NULL) { + fn = dir_path + std::string(ent->d_name); + ext = fn.substr(fn.length()-4, fn.length()); + if(ext.compare(file_type) == 0) { + sam_files.push_back(fn); + } + } + closedir(dir); + + return sam_files; +} + +#endif /* DIR_UTIL_H */