mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-20 21:33:40 -07:00
git subrepo clone https://github.com/HarbourMasters/ZAPDTR.git
subrepo: subdir: "ZAPDTR" merged: "a53a53ea4" upstream: origin: "https://github.com/HarbourMasters/ZAPDTR.git" branch: "master" commit: "a53a53ea4" git-subrepo: version: "0.4.1" origin: "???" commit: "???"
This commit is contained in:
parent
f52a2a6406
commit
5dda5762ba
217 changed files with 47152 additions and 0 deletions
73
ZAPDTR/ZAPDUtils/Utils/Directory.h
Normal file
73
ZAPDTR/ZAPDUtils/Utils/Directory.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#if __has_include(<filesystem>)
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
#else
|
||||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#endif
|
||||
|
||||
#include "StringHelper.h"
|
||||
|
||||
#undef GetCurrentDirectory
|
||||
#undef CreateDirectory
|
||||
|
||||
class Directory
|
||||
{
|
||||
public:
|
||||
#ifndef PATH_HACK
|
||||
static std::string GetCurrentDirectory() { return fs::current_path().u8string().c_str(); }
|
||||
#endif
|
||||
|
||||
static bool Exists(const fs::path& path) { return fs::exists(path); }
|
||||
|
||||
// Stupid hack because of Windows.h
|
||||
static void MakeDirectory(const std::string& path)
|
||||
{
|
||||
CreateDirectory(path);
|
||||
}
|
||||
|
||||
static void CreateDirectory(const std::string& path)
|
||||
{
|
||||
|
||||
#ifdef _MSC_VER
|
||||
std::string splitChar = "\\";
|
||||
#else
|
||||
std::string splitChar = "/";
|
||||
#endif
|
||||
|
||||
std::string curPath;
|
||||
std::vector<std::string> split = StringHelper::Split(path, splitChar);
|
||||
|
||||
for (std::string s : split)
|
||||
{
|
||||
curPath += s + splitChar;
|
||||
|
||||
if (!Exists(curPath))
|
||||
fs::create_directory(curPath);
|
||||
}
|
||||
|
||||
// fs::create_directory(path);
|
||||
}
|
||||
|
||||
static std::vector<std::string> ListFiles(const std::string& dir)
|
||||
{
|
||||
std::vector<std::string> lst;
|
||||
|
||||
if (Directory::Exists(dir))
|
||||
{
|
||||
for (auto& p : fs::recursive_directory_iterator(dir))
|
||||
{
|
||||
if (!p.is_directory())
|
||||
lst.push_back(p.path().string());
|
||||
}
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue