-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesys.cpp
68 lines (58 loc) · 1.35 KB
/
filesys.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
#include "filesys.h"
namespace fs = std::filesystem;
wxString getCurrentDir()
{
wxString s = wxGetCwd();
return s;
}
std::string getExtension(const std::string& _file)
{
auto ext = fs::path(_file).extension();
return ext.string();
}
std::string getFileName(const std::string& _file)
{
auto fname = fs::path(_file).filename();
return fname.string();
}
std::string getPathOfFile(const std::string& _file)
{
auto fpath = fs::path(_file).parent_path();
return fpath.string();
}
bool file_exists(const std::string& file)
{
return fs::exists(file);
}
uintmax_t getFileSize(const std::string& _file)
{
std::filesystem::directory_entry File{ _file };
return File.file_size();
}
// you can add try catches to every call, this is only an example
bool directory_exists(const std::string& _directory)
{
try
{
std::filesystem::directory_entry Directory{ _directory };
return Directory.exists();
}
catch (std::filesystem::filesystem_error e)
{
return false;
}
}
bool is_directory(const std::string& _directory)
{
std::filesystem::directory_entry Directory{ _directory };
return Directory.is_directory();
}
bool is_file(const std::string& _directory)
{
std::filesystem::directory_entry Directory{ _directory };
return Directory.is_regular_file();
}
bool create_dir(const std::string& _directory)
{
return std::filesystem::create_directory(_directory);
}