13[[nodiscard]]
bool read_file(
const std::filesystem::path& pathname, std::string& output);
16[[nodiscard]]
bool write_file(
const std::filesystem::path& pathname,
const std::string& str);
19[[nodiscard]]
bool path_exists(
const std::string& pathname);
22[[nodiscard]] std::vector<std::string>
list_files(
const std::string& pathname);
24using file_ptr = std::unique_ptr<FILE,
decltype([](FILE *f) {
29 FILE *f =
::fopen(filename, mode);
35inline bool mkdir(
const std::filesystem::path& path) {
37 return std::filesystem::create_directory(path, ec);
42inline bool mkdirp(
const std::filesystem::path& path) {
44 return std::filesystem::create_directories(path, ec);
Definition: algorithm.h:10
bool read_file(const std::filesystem::path &pathname, std::string &output)
read all from pathname, append to output
Definition: file.cpp:9
bool write_file(const std::filesystem::path &pathname, const std::string &str)
write all to pathname
Definition: file.cpp:27
std::vector< std::string > list_files(const std::string &pathname)
list all files(including directories) in pathname recursively and sort by names
Definition: file.cpp:41
bool mkdirp(const std::filesystem::path &path)
Definition: file.h:42
bool mkdir(const std::filesystem::path &path)
Definition: file.h:35
bool path_exists(const std::string &pathname)
check path(file or directory) exists
Definition: file.cpp:36
file_ptr fopen(const char *filename, char const *mode)
Definition: file.h:28
std::unique_ptr< FILE, decltype([](FILE *f) { if(f) fclose(f) file_ptr
Definition: file.h:25