-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileAction.cpp
74 lines (66 loc) · 1.83 KB
/
FileAction.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "FileAction.h"
#include <filesystem>
FileAction::FileAction(/* args */)
{
}
FileAction::~FileAction()
{
}
bool FileAction::dirExists(const std::string& dirPath)
{
std::filesystem::path path(dirPath);
return std::filesystem::exists(path);
}
bool FileAction::fileExists(const std::string& filePath)
{
std::filesystem::path path(filePath);
return std::filesystem::exists(path);
}
bool FileAction::makeDir(const std::string& dirPath)
{
std::filesystem::path path(dirPath);
return std::filesystem::create_directory(path);
}
std::vector<FileInfo> FileAction::listOfDir(const std::string& filePath,bool bIterate)
{
using namespace std;
filesystem::path path(filePath);
if(!filesystem::exists(path))
return std::vector<FileInfo>();
/* file */
if(!filesystem::is_directory(path))
{
FileInfo fInfo;
fInfo.fullPath = filePath;
fInfo.fileName = filePath.substr(filePath.find_last_of("/")+1, filePath.size()-2 - filePath.find_last_of("/"));
fInfo.isDir = false;
return { fInfo };
}
/* dir */
std::vector<FileInfo> dir_list;
if(bIterate)
{
filesystem::recursive_directory_iterator it_dir(path);
for (auto it : it_dir)
{
FileInfo fInfo;
fInfo.fullPath = it.path().string();
fInfo.fileName = it.path().filename().string();
fInfo.isDir = it.is_directory();
dir_list.emplace_back(fInfo);
}
}
else
{
filesystem::directory_iterator it_dir(path);
for (auto it : it_dir)
{
FileInfo fInfo;
fInfo.fullPath = it.path().string();
fInfo.fileName = it.path().filename().string();
fInfo.isDir = it.is_directory();
dir_list.emplace_back(fInfo);
}
}
return dir_list;
}