Files
OpenVulkano/openVulkanoCpp/IO/FsUtils.hpp
2025-06-06 14:34:35 +02:00

68 lines
1.8 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Math/ByteSize.hpp"
#include <filesystem>
namespace OpenVulkano
{
struct FsCount
{
size_t fileCount = 0, dirCount = 0;
[[maybe_unused]] [[nodiscard]] size_t GetTotalEntryCount() const { return fileCount + dirCount; }
FsCount& operator +=(const FsCount& other)
{
fileCount += other.fileCount;
dirCount += other.dirCount;
return *this;
}
FsCount operator +(FsCount other)
{
return other += *this;
}
FsCount& operator -=(const FsCount& other)
{
fileCount -= other.fileCount;
dirCount -= other.dirCount;
return *this;
}
FsCount operator -(FsCount other)
{
return other -= *this;
}
};
struct FsUtils
{
static bool DeleteEmptyFilesAndDirs(const std::filesystem::path& dir, bool recursive = true);
static bool DeleteEmptyDirs(const std::filesystem::path& dir, bool recursive = true);
static bool DeleteEmptySubTrees(const std::filesystem::path& dir);
static bool IsTreeEmpty(const std::filesystem::path& dir);
[[nodiscard]] static ByteSize GetDirSize(const std::filesystem::path& dir);
[[nodiscard]] static FsCount GetDirFileAndDirCount(const std::filesystem::path& dir);
[[nodiscard]] static std::string ToValidFileName(std::string filename);
[[maybe_unused]] [[nodiscard]] static std::vector<std::filesystem::path> FilesWithExtension(const std::filesystem::path& dir, std::string ext);
[[nodiscard]] static std::string EnsureExtension(const std::string& filename, const std::string_view& extension);
[[nodiscard]] static bool FileContains(const std::filesystem::path& path, const std::string_view& searchString);
};
}