libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Directory.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <iostream>
6
7#if __has_include(<filesystem>)
8#include <filesystem>
9namespace fs = std::filesystem;
10#else
11#include <experimental/filesystem>
12namespace fs = std::experimental::filesystem;
13#endif
14
15#include <spdlog/spdlog.h>
16
17#undef GetCurrentDirectory
18#undef CreateDirectory
19
25class Directory {
26 public:
27#ifndef PATH_HACK
32 static std::string GetCurrentDirectory() {
33 return fs::current_path().string();
34 }
35#endif
36
42 static bool Exists(const fs::path& path) {
43 return fs::exists(path);
44 }
45
53 static void MakeDirectory(const std::string& path) {
54 CreateDirectory(path);
55 }
56
61 static void CreateDirectory(const std::string& path) {
62 try {
63 fs::create_directories(path);
64 } catch (const std::exception& e) { SPDLOG_ERROR("Failed to create directory {}: {}", path, e.what()); }
65 }
66
72 static std::vector<std::string> ListFiles(const std::string& dir) {
73 std::vector<std::string> lst;
74
75 if (Exists(dir)) {
76 for (auto& p : fs::recursive_directory_iterator(dir)) {
77 if (!p.is_directory())
78 lst.push_back(p.path().generic_string());
79 }
80 }
81
82 return lst;
83 }
84};