Size: 1067 bytes.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// cs/fs/fs.hh
#ifndef CS_FS_FS_HH
#define CS_FS_FS_HH

#include <sstream>
#include <string>

#include "cs/result.hh"

namespace cs::fs {
cs::ResultOr<std::vector<std::string>> ls(std::string path);
cs::ResultOr<std::string> read(std::string path);
cs::Result write(std::string path, std::string contents);
cs::ResultOr<std::string> cwd();
cs::Result mkdir(std::string path);
cs::Result Delete(std::string path);
bool dir_exists(std::string path);
bool IsDir(std::string path);
bool IsFile(std::string path);

// Source:
// https://chatgpt.com/canvas/shared/67eb48720dc881918e7c87c05042cb39
template <typename... Args>
std::string Join(const Args&... args) {
  std::stringstream result;
  bool first = true;

  auto process = [&](const std::string& path) {
    std::string trimmed = path;
    while (!trimmed.empty() && trimmed.back() == '/') {
      trimmed.pop_back();
    }

    if (!first) {
      result << "/";
    }
    result << trimmed;
    first = false;
  };

  (process(args), ...);

  return result.str();
}
}  // namespace cs::fs

#endif  // CS_FS_FS_HH
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-3:8080 in 4ms.