методы копирования

This commit is contained in:
2023-12-04 18:42:20 +03:00
parent 3f9ba0feb3
commit 11fae0bc4e
5 changed files with 37 additions and 16 deletions

View File

@@ -31,8 +31,13 @@ public:
//https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program
static void Chmod(const String& path) {
String command = "chmod 777 " + String::DQuotes(path);
system(command.getCharArray());
#if __cplusplus >= 201703L
std::filesystem::permissions(path.getCharArray(), std::filesystem::perms::all);
#else
String command = "chmod 777 " + String::DQuotes(path);
int i=system(command.getCharArray());
printf("chmod 777 '%s' return code = %d\n", path.getCharArray(), i);
#endif
}
//https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c
@@ -47,9 +52,23 @@ public:
std::this_thread::sleep_for(timespan);
}
static void Copy(const String& src, const String& dst) {
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
system(command.getCharArray());
#if __cplusplus >= 201703L
std::filesystem::copy(src.getCharArray(), dst.getCharArray());
#else
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
int i = system(command.getCharArray());
printf("cp '%s' return code = %d\n",src.getCharArray(), i);
#endif
}
static void CopyDirectory(const String& src, const String& dst) {
#if __cplusplus >= 201703L
std::filesystem::copy((src+ "/.").getCharArray(), dst.getCharArray(), std::filesystem::copy_options::recursive);
#else
String command = "cp -r " + String::DQuotes(src + "/.") + " " + String::DQuotes(dst);
int i = system(command.getCharArray());
printf("cp -r '%s' return code = %d\n",src.getCharArray(),i);
#endif
}
static time_t getAbsoluteTime() {
return time(NULL);
}
@@ -58,8 +77,4 @@ public:
String res(ctime(&ttime));
return res;
}
static void ZipFolder(const String& src, const String& dst) {
String command = "zip -r " + String::DQuotes(dst) + " " + String::DQuotes(src);
system(command.getCharArray());
}
};