tv_rename/filesystem.hpp

77 lines
1.7 KiB
C++

#ifndef FSLIB_H
#define FSLIB_H
#include <string>
#include <dirent.h>
#include <string.h>
namespace FSLib{
bool exists(const std::string &path);
bool isDirectory(const std::string &path);
std::string canonical(const std::string &path);
bool rename(const std::string &file_a, const std::string &file_b);
class Directory {
public:
Directory(const std::string &path_) : dir_path(path_) {}
Directory() = delete;
Directory(const Directory &d) = default;
Directory(Directory &&d) = default;
class Iterator {
public:
Iterator( const Directory &d_ ) : d(opendir(d_.path())) {
current_entry = readdir(d);
}
Iterator( const Directory &d_, const struct dirent *current_entry_) : d(opendir(d_.path())), current_entry(current_entry_) {}
Iterator() = delete;
Iterator(const Iterator &i) = default;
Iterator(Iterator &&i) = default;
~Iterator() {
closedir(d);
}
std::string operator*();
Iterator &operator++();
Iterator operator++(int);
bool operator==(const Iterator &i_other);
bool operator!=(const Iterator &i_other);
private:
DIR *d;
const struct dirent *current_entry;
};
using iterator = Iterator;
using const_iterator = Iterator;
iterator begin();
const_iterator begin() const;
const_iterator cbegin() const;
iterator end();
const_iterator end() const;
const_iterator cend() const;
const char *path() const;
private:
std::string dir_path;
};
} //end FSLib
#endif