-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.cpp
48 lines (42 loc) · 1.01 KB
/
helper.cpp
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
48
#define LOG_TAG "Helper"
#include "helper.h"
Helper::Helper()
{
}
std::string Helper::basename(const std::string &pathname)
{
return {std::find_if(pathname.rbegin(), pathname.rend(),
[](char c) { return c == '/'; })
.base(),
pathname.end()};
}
std::vector<std::string> Helper::listDirectory(const std::string &path, const std::string &)
{
std::vector<std::string> vec;
DIR *dir = opendir(path.c_str());
if (dir != nullptr)
{
struct dirent *entry;
while ((entry = readdir(dir)) != nullptr)
{
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
{
continue;
}
else
{
std::string fullpath(path);
fullpath += entry->d_name;
vec.push_back(fullpath);
}
}
}
else
{
ALOGD("Failed to open %s", path.c_str());
}
return vec;
}
Helper::~Helper()
{
}