-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_utilities.h
61 lines (52 loc) · 1.75 KB
/
file_utilities.h
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
#ifndef FILEITERATOR_H
#define FILEITERATOR_H
#include <filesystem>
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <iostream>
//Try to resolve different FS implementations
#if defined(Q_OS_WIN)
namespace fs = std::experimental::filesystem;
#elif defined(Q_OS_LINUX)
namespace fs = std::filesystem;
#elif defined(Q_OS_MAC)
namespace fs = std::filesystem;
#else
namespace fs = std::filesystem;
#endif
namespace fileUtilities {
template<class iterclass>
void populateList(iterclass& iter, std::vector<std::string>& paths,
std::vector<std::string>& filenames);
void fileWalker (const char * root_dir, std::vector<std::string>& paths,
std::vector<std::string>& filenames, bool recursive, std::string& error);
bool checkIfExistOrDir(const char * path);
int checkIfWritable(const char * path);
bool checkIfImagesExist (const char * path, bool recursive, std::string& error);
} //namespace
class fileCopier {
public:
fs::path savedir;
fileCopier(const char * path) : savedir(path) {
// create the target folder if it doesn't exist
if (!fs::is_directory(path) || !fs::exists(path)) {
fs::create_directory(path);
}
}
void copy(std::string& path) {
fs::path filepath(path);
fs::path hypofile = fs::path(savedir.u8string() + std::string("/") + filepath.filename().u8string());
if (!fs::exists(hypofile)) {
fs::copy(filepath, savedir);
}
}
void uncopy(std::string& path) {
fs::path origfile(path);
fs::path hypofile = fs::path(savedir.u8string() + std::string("/") + origfile.filename().u8string());
if (fs::exists(hypofile)) {
fs::remove(hypofile);
}
}
};
#endif // FILEITERATOR_H