libmrbesen/inc/files.h

33 lines
1.0 KiB
C++

#pragma once
#include <functional>
#include <iterator>
#include <string>
namespace mrbesen::Files {
void parent(const std::string& child, std::string& out); //get the parent directory of a file or directory path
void file(const std::string& path, std::string& out); //get the filename without the path
void extention(const std::string& path, std::string& ext); //get the files extenetion
enum class FileType : unsigned char {
UNKNOWN = 0,
FIFO = 1,
CHARACTER = 2,
DIRECTORY = 4,
BLOCK = 6,
REGULAR = 8,
LINK = 10,
SOCKET = 12,
WHT = 14 ///????
//copied from dirent.h -> see man readdir
};
typedef std::function<bool(const std::string&, FileType type)> fileNameFilter;
typedef std::function<void(const std::string&, FileType type)> fileCallback;
template<class Container>
bool scan(const std::string& path, std::insert_iterator<Container> it, bool prefixdir = false, fileNameFilter fnf = fileNameFilter(nullptr));
bool scan(const std::string& path, fileCallback clb, bool prefixdir = false, fileNameFilter fnf = fileNameFilter(nullptr));
}