-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathDirlist.hh
47 lines (37 loc) · 1.2 KB
/
Dirlist.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
copyright 2006-2017 Paul Dreik (earlier Paul Sundvall)
Distributed under GPL v 2.0 or later, at your option.
See LICENSE for further details.
*/
#ifndef Dirlist_hh
#define Dirlist_hh
#include <string>
/// class that traverses a directory
class Dirlist
{
public:
// constructor
explicit Dirlist(bool followsymlinks)
: m_followsymlinks(followsymlinks)
, m_callback(nullptr)
{
}
private:
// follow symlinks or not
bool m_followsymlinks;
// where to report found files. this is called for every item in all
// directories found by walk.
typedef int (*reportfcntype)(const std::string&, const std::string&, int);
// called when a regular file or a symlink is encountered
reportfcntype m_callback;
// a function that is called from walk when a non-directory is encountered
// for instance,if walk("/path/to/a/file.ext") is called instead of
// walk("/path/to/a/")
int handlepossiblefile(const std::string& possiblefile, int recursionlevel);
public:
// find all files on a specific place
int walk(const std::string& dir, const int recursionlevel = 0);
// to set the report functions
void setcallbackfcn(reportfcntype reportfcn) { m_callback = reportfcn; }
};
#endif