Add Folder check and Folder creation

This commit is contained in:
2023-03-16 13:41:53 +01:00
parent 5f3d3d78b7
commit c26e48e43c
13 changed files with 376 additions and 61 deletions
+46
View File
@@ -0,0 +1,46 @@
#include "Util.h"
#include <array>
#include <ctime>
#include <filesystem/path.h>
#include <sys/types.h>
#include <sys/stat.h>
namespace CameraRecorder {
namespace Util {
std::string GetDateTimeString(bool omitSeparator)
{
std::array<char, 17> buffer;
buffer.fill(0);
std::time_t t = std::time(nullptr);
std::tm* tm = std::localtime(&t);
if (omitSeparator)
strftime(buffer.data(), sizeof(buffer), "%Y%m%d%H%M%S", tm);
else
strftime(buffer.data(), sizeof(buffer), "%Y%m%d-%H%M%S", tm);
return buffer.data();
}
bool FolderExists(const std::string& path)
{
struct stat info;
if (stat(path.c_str(), &info) != 0)
return false;
else if (info.st_mode & S_IFDIR)
return true;
else
return false;
}
void CreateFolder(const std::string& path)
{
int status = mkdir(path.c_str(), 0777);
if ((status < 0) && (errno != EEXIST))
throw std::runtime_error("Can't create folder.");
}
} // namespace Util
} // namespace CameraRecorder