aboutsummaryrefslogtreecommitdiff
path: root/include/FileUtil.hpp
blob: 5b91aad83b9289553498cd537ba4dca5344a2112 (plain)
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
#ifndef SIBS_FILEUTIL_HPP
#define SIBS_FILEUTIL_HPP

#include "../external/tinydir.h"
#include "Result.hpp"
#include "StringView.hpp"
#include <functional>

namespace sibs
{
    using FileWalkCallbackFunc = std::function<void(tinydir_file*)>;

    enum class FileType
    {
        FILE_NOT_FOUND,
        REGULAR,
        DIRECTORY
    };

    FileType getFileType(const char *path);
    void walkDir(const char *directory, FileWalkCallbackFunc callbackFunc);
    void walkDirFiles(const char *directory, FileWalkCallbackFunc callbackFunc);
    void walkDirFilesRecursive(const char *directory, FileWalkCallbackFunc callbackFunc);
    Result<StringView> getFileContent(const char *filepath);
    Result<bool> fileOverwrite(const char *filepath, StringView data);
    const char* getHomeDir();
    Result<std::string> getCwd();
    // Note: Will not delete created directories if this operation fails for some reason
    Result<bool> createDirectoryRecursive(const char *path);
}

#endif //SIBS_FILEUTIL_HPP