Mercurial > repos > chrisd > testing
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f95150c37d38 |
---|---|
1 #ifndef DIR_UTIL_H | |
2 #define DIR_UTIL_H | |
3 | |
4 #include <list> | |
5 #include <iostream> | |
6 #include <string> | |
7 #include <dirent.h> | |
8 | |
9 /* | |
10 * Parses a directory of sam files | |
11 */ | |
12 static inline std::list<std::string> | |
13 parse_sam_dir(const std::string &directory) { | |
14 DIR *dir; | |
15 struct dirent *ent; | |
16 std::string dir_path = directory; | |
17 | |
18 dir = opendir(dir_path.c_str()); | |
19 // is dir open/valid? | |
20 if(dir == NULL) { | |
21 std::cout << "Not a valid directory" << std::endl; | |
22 exit(EXIT_FAILURE); | |
23 } | |
24 | |
25 std::list<std::string> sam_files; | |
26 std::string fn; | |
27 std::string ext; | |
28 std::string file_type = ".sam"; | |
29 | |
30 // get all files with a .sam file extension | |
31 while((ent = readdir(dir)) != NULL) { | |
32 fn = dir_path + std::string(ent->d_name); | |
33 ext = fn.substr(fn.length()-4, fn.length()); | |
34 if(ext.compare(file_type) == 0) { | |
35 sam_files.push_back(fn); | |
36 } | |
37 } | |
38 closedir(dir); | |
39 | |
40 return sam_files; | |
41 } | |
42 | |
43 #endif /* DIR_UTIL_H */ |