aboutsummaryrefslogtreecommitdiff
path: root/include/FileUtil.hpp
blob: 5d1594a10d5d45b64d958a5be946a186f081c05d (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
33
#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);
    Result<std::string> getRealPath(const char *path);
}

#endif //SIBS_FILEUTIL_HPP