- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectory.cpp
More file actions
Latest commit
18 lines (15 loc) · 556 Bytes
/
Copy pathDirectory.cpp
File metadata and controls
18 lines (15 loc) · 556 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include"Directory.h"
usingnamespacestd;
Directory::Directory(const string& path) : _directory(opendir(path.c_str())) { }
vector<string> Directory::matching_filenames(function<bool (const string&)> predicate) {
vector<string> result;
while(structdirent* ent = readdir(_directory)) {
if(predicate(ent->d_name))
result.emplace_back(ent->d_name);
}
return result;
//Important: the directory is not rewound because it does not need to be for our use cases.
}
Directory::~Directory() {
closedir(_directory);
}