Mercurial > repos > chrisd > testshed
comparison gene_fraction/src/dir_util.h @ 0:0fd352f62446 draft default tip
planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
author | chrisd |
---|---|
date | Sun, 21 Feb 2016 06:05:24 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0fd352f62446 |
---|---|
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 */ |