parent
d48d082e6b
commit
9608bb05c8
2 changed files with 80 additions and 0 deletions
@ -0,0 +1,34 @@ |
||||
#include "directory.h" |
||||
|
||||
namespace Bk::Tools { |
||||
std::string Directory::current() |
||||
{ |
||||
return std::filesystem::current_path(); |
||||
} |
||||
|
||||
int Directory::remove() |
||||
{ |
||||
return std::filesystem::remove_all(ent.path()); |
||||
} |
||||
|
||||
void Directory::copy(std::string path, CopyOption opt) |
||||
{ |
||||
if (exists()) std::filesystem::copy(ent.path(), path, opt); |
||||
} |
||||
|
||||
std::vector<DirEntry> Directory::entries() |
||||
{ |
||||
std::vector<DirEntry> entries; |
||||
for (std::filesystem::directory_entry entry : std::filesystem::directory_iterator(ent.path())) |
||||
entries.push_back(DirEntry(entry)); |
||||
return entries; |
||||
} |
||||
|
||||
std::vector<DirEntry> Directory::r_entries() |
||||
{ |
||||
std::vector<DirEntry> entries; |
||||
for (std::filesystem::directory_entry entry : std::filesystem::recursive_directory_iterator(ent.path())) |
||||
entries.push_back(DirEntry(entry)); |
||||
return entries; |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
#pragma once |
||||
|
||||
#include <bakatoolspch.h> |
||||
#include "dir_entry.h" |
||||
|
||||
namespace Bk::Tools { |
||||
class Directory : public DirEntry |
||||
{ |
||||
public: |
||||
Directory(std::string path) |
||||
: DirEntry(path) {} |
||||
|
||||
Directory(std::filesystem::directory_entry ent) |
||||
: DirEntry(ent) {} |
||||
|
||||
virtual ~Directory() {} |
||||
|
||||
int remove() override; |
||||
void copy(std::string path, CopyOption opt = CopyOption::recursive) override; |
||||
|
||||
std::vector<DirEntry> entries(); |
||||
std::vector<DirEntry> r_entries(); |
||||
|
||||
template<typename E> |
||||
std::vector<E> entries() |
||||
{ |
||||
std::vector<E> entries; |
||||
for (std::filesystem::directory_entry entry : std::filesystem::directory_iterator(ent.path())) |
||||
if (E::get_type() == entry.status().type()) entries.push_back(E(entry)); |
||||
return entries; |
||||
} |
||||
|
||||
template<typename E> |
||||
std::vector<E> r_entries() |
||||
{ |
||||
std::vector<E> entries; |
||||
for (std::filesystem::directory_entry entry : std::filesystem::recursive_directory_iterator(ent.path())) |
||||
if (E::get_type() == entry.status().type()) entries.push_back(E(entry)); |
||||
return entries; |
||||
} |
||||
|
||||
static std::string current(); |
||||
|
||||
BK_DIR_ENTRY_TYPE(directory) |
||||
}; |
||||
} |
Loading…
Reference in New Issue