ES-DE/es-core/src/utils/FileSystemUtil.h

100 lines
4.2 KiB
C
Raw Normal View History

// SPDX-License-Identifier: MIT
2020-06-22 15:27:53 +00:00
//
// ES-DE
2020-06-22 15:27:53 +00:00
// FileSystemUtil.h
//
// Low-level filesystem functions.
// Resolve relative paths, resolve symlinks, create directories,
// remove files etc.
2020-06-22 15:27:53 +00:00
//
2017-11-22 21:29:52 +00:00
#ifndef ES_CORE_UTILS_FILE_SYSTEM_UTIL_H
#define ES_CORE_UTILS_FILE_SYSTEM_UTIL_H
#include <filesystem>
#include <list>
#include <string>
class FileSystemVariables
{
public:
static inline std::filesystem::path sAppDataDirectory;
};
namespace Utils
{
2020-06-22 15:27:53 +00:00
namespace FileSystem
{
using StringList = std::list<std::string>;
using FileList = std::list<std::filesystem::path>;
StringList getDirContent(const std::string& path, const bool recursive = false);
FileList getDirContentSTD(const std::filesystem::path& path, const bool recursive = false);
StringList getMatchingFiles(const std::string& pattern);
StringList getPathList(const std::string& path);
void setHomePath(const std::string& path);
2020-06-22 15:27:53 +00:00
std::string getHomePath();
std::filesystem::path getHomePathSTD();
std::string getSystemHomeDirectory();
std::filesystem::path getAppDataDirectory();
std::filesystem::path getInternalAppDataDirectory();
2020-07-10 17:53:33 +00:00
std::string getPathToBinary(const std::string& executable);
void setExePath(const std::string& path);
2020-06-22 15:27:53 +00:00
std::string getExePath();
std::filesystem::path getExePathSTD();
std::string getEsBinary();
std::filesystem::path getEsBinarySTD();
std::filesystem::path getProgramDataPath();
std::string getPreferredPath(const std::string& path);
std::string getGenericPath(const std::string& path);
std::string getEscapedPath(const std::string& path);
std::string getCanonicalPath(const std::string& path);
std::filesystem::path getCanonicalPathSTD(const std::filesystem::path& path);
std::string getAbsolutePath(
const std::string& path,
const std::string& base = std::filesystem::current_path().string());
std::string getParent(const std::string& path);
std::string getFileName(const std::string& path);
std::filesystem::path getFileNameSTD(const std::filesystem::path& path);
std::string getStem(const std::string& path);
std::string getExtension(const std::string& path);
long getFileSize(const std::filesystem::path& path);
std::string expandHomePath(const std::string& path);
std::string resolveRelativePath(const std::string& path,
const std::string& relativeTo,
const bool allowHome);
std::string createRelativePath(const std::string& path,
const std::string& relativeTo,
const bool allowHome);
std::string removeCommonPath(const std::string& path,
const std::string& commonArg,
bool& contains);
std::string resolveSymlink(const std::string& path);
bool copyFile(const std::string& sourcePath,
const std::string& destinationPath,
bool overwrite);
bool renameFile(const std::string& sourcePath,
const std::string& destinationPath,
bool overwrite);
bool createEmptyFile(const std::filesystem::path& path);
bool removeFile(const std::string& path);
bool removeDirectory(const std::string& path, bool recursive);
bool createDirectory(const std::string& path);
bool exists(const std::string& path);
bool existsSTD(const std::filesystem::path& path);
bool driveExists(const std::string& path);
bool isAbsolute(const std::string& path);
bool isRegularFile(const std::string& path);
bool isRegularFileSTD(const std::filesystem::path& path);
bool isDirectory(const std::string& path);
bool isDirectorySTD(const std::filesystem::path& path);
bool isSymlink(const std::string& path);
bool isSymlinkSTD(const std::filesystem::path& path);
bool isHidden(const std::string& path);
} // namespace FileSystem
} // namespace Utils
2017-11-22 21:29:52 +00:00
#endif // ES_CORE_UTILS_FILE_SYSTEM_UTIL_H