41 std::vector<std::string> files;
43 std::vector<std::string> ret;
45 std::regex reg(search, std::regex::ECMAScript);
48 for (
const auto& entry : std::filesystem::directory_iterator(path)) {
49 files.push_back(entry.path().generic_string());
51 }
catch (std::exception& e) {
55 for (
auto elem : files) {
56 if (std::regex_match(elem, reg)) {
65 std::vector<std::string> files;
67 std::vector<std::string> ret;
70 for (
const auto& entry : std::filesystem::directory_iterator(path)) {
71 files.push_back(entry.path().generic_string());
73 }
catch (std::exception& e) {
77 for (
auto elem : files) {
87 std::vector<std::string> files;
89 std::vector<std::string> ret;
91 std::regex reg(search);
94 for (
const auto& entry : std::filesystem::recursive_directory_iterator(path)) {
95 files.push_back(entry.path().generic_string());
97 }
catch (std::exception& e) {
101 for (
auto elem : files) {
102 if (std::regex_match(elem, reg)) {
111 std::vector<std::string> files;
113 std::vector<std::string> ret;
116 for (
const auto& entry : std::filesystem::recursive_directory_iterator(path)) {
117 files.push_back(entry.path().generic_string());
119 }
catch (std::exception& e) {
123 for (
auto elem : files) {
133 std::filesystem::path from, to;
139 std::filesystem::rename(from, to);
140 }
catch (std::exception& e) {
149 std::filesystem::path p;
155 if (std::filesystem::remove_all(p) == 0) {
159 }
catch (std::exception& e) {
168 if (std::filesystem::remove(p) ==
false)
170 }
catch (std::exception& e) {
180 std::filesystem::path from, to;
185 std::filesystem::copy(from, to, std::filesystem::copy_options::recursive);
186 }
catch (std::exception& e) {
195 std::filesystem::path from, to;
200 std::filesystem::copy(from, to);
203 }
catch (std::exception& e) {
216 std::string path =
"";
219 }
catch (std::exception& e) {
221 throw std::runtime_error(
"Invalid count of elements");
226 std::ofstream file(path);
230 }
catch (std::exception& e) {
239 std::filesystem::path p;
241 p.assign(paths.at(0));
242 }
catch (std::exception& e) {
244 throw std::runtime_error(
"Invalid count of elements");
249 std::filesystem::create_directory(p);
250 }
catch (std::exception& e) {
258 std::filesystem::path file, link;
260 file.assign(paths.at(0));
261 }
catch (std::exception& e) {
263 throw std::runtime_error(
"Invalid count of elements");
267 link.assign(paths.at(1));
268 }
catch (std::exception& e) {
270 throw std::runtime_error(
"Invalid count of elements");
275 std::filesystem::create_symlink(file, link);
276 }
catch (std::exception& e) {
285 std::filesystem::path directory, link;
287 directory.assign(paths.at(0));
288 }
catch (std::exception& e) {
290 throw std::runtime_error(
"Invalid count of elements");
294 link.assign(paths.at(1));
295 }
catch (std::exception& e) {
297 throw std::runtime_error(
"Invalid count of elements");
302 std::filesystem::create_directory_symlink(directory, link);
303 }
catch (std::exception& e) {
311 std::filesystem::path element, link;
313 element.assign(paths.at(0));
314 }
catch (std::exception& e) {
316 throw std::runtime_error(
"Invalid count of elements");
320 link.assign(paths.at(1));
321 }
catch (std::exception& e) {
323 throw std::runtime_error(
"Invalid count of elements");
328 std::filesystem::create_hard_link(element, link);
329 }
catch (std::exception& e) {
336 throw std::runtime_error(
"Invalid type of new element");
344 std::filesystem::path p;
346 return std::filesystem::exists(p);
349 if (base_path == std::string(
"")) {
350 return std::filesystem::canonical(std ::filesystem::path(path));
352 return std::filesystem::canonical(std::filesystem::path(base_path) /
353 std ::filesystem::path(path));
357 if (base_path == std::string(
"")) {
360 return std::filesystem::relative(std::filesystem::path(base_path) /
361 std ::filesystem::path(path),
366 return std::filesystem::path(file).parent_path();
369 return std::filesystem::current_path();
std::string normalize_path(std::string path, std::string base_path="")
Get absolute path to file using relative path and base path.
bool exists(std::string path)
Check if file exists.
bool create(std::vector< std::string > paths, CBuild::fs::type what)
Create element.
std::string base(std::string file)
Get base file path (path to dir in what file is)
bool remove(std::string path, bool force=false)
Delete files or directories.
std::string curr_path()
Get current working dir of CBuild.run process.
std::string normalize_relative_path(std::string path, std::string base_path="")
Get absolute path to file using relative path and base path.
bool copy(std::string start, std::string end)
Copy files or directories.
type
Type for element creating.
@ DIRECTORY
Standard directory.
@ HARDLINK
Standard hardlink (can be unsupported or supported partially) (though std::filesystem::create_hard_li...
@ SYMLINK_DIR
Alias for SYMLINK_DIRECTORY.
@ SYMLINK_FILE
Standard symlink (can be unsupported or supported partially) (thought std::filesystem::create_symlink...
@ SYMLINK_DIRECTORY
Standard symlink (can be unsupported or supported partially) (std::filesystem::create_directory_symli...
@ DIR
Alias for DIRECTORY.
bool move(std::string start, std::string end)
Move files or directories, remove starting files or directories.
std::vector< std::string > dir_rec(std::string path, std::string search)
Recursively search files using provided regex.
std::regex c_cpp_file(".*\\.(cpp|cxx|cc|c)")
bool rename(std::string start, std::string end)
Rename files or directories,.
std::vector< std::string > dir(std::string path, std::string search)
Search files using provided regex.
Filebuffer for CBuild ecosystem.
void void printf_full(color fg, const char *fmt,...) __attribute__((format(printf
Some poor printf implementation for verbouse-only prints.
Custom print that support color codes.