Added GetAllFiles to filesystem

This commit is contained in:
antopilo
2024-12-01 13:21:44 -05:00
parent b6c3220797
commit ea044a2357
2 changed files with 30 additions and 0 deletions

View File

@@ -64,6 +64,34 @@ bool FileSystem::FileExists(const std::string& path, bool absolute)
return std::filesystem::exists(fullPath) && std::filesystem::is_regular_file(fullPath);
}
std::vector<Ref<File>> FileSystem::GetAllFiles(const FileType fileType)
{
std::vector<Ref<File>> foundFiles;
std::function<void(Ref<Directory>)> scanDir;
scanDir = [scanDir, &foundFiles, fileType](Ref<Directory> dir)
{
// All the files matching the filetype
for (auto& f : dir->Files)
{
if (f->GetFileType() == fileType)
{
foundFiles.push_back(f);
}
}
// Scan sub folder
for (auto& d : dir->Directories)
{
scanDir(d);
}
};
scanDir(RootDirectory);
return foundFiles;
}
void FileSystem::SetRootDirectory(const std::string path)
{
Root = path;

View File

@@ -1,5 +1,6 @@
#pragma once
#include "src/Core/Core.h"
#include "FileTypes.h"
namespace filewatch
{
@@ -35,6 +36,7 @@ namespace Nuake
static bool MakeDirectory(const std::string& path, bool absolute = false);
static bool DirectoryExists(const std::string& path, bool absolute = false);
static bool FileExists(const std::string& path, bool absolute = false);
static std::vector<Ref<File>> GetAllFiles(const FileType fileType);
static std::string ReadFile(const std::string& path, bool absolute = false);
static void CopyFileAbsolute(const std::string& src, const std::string& dest);