#pragma once #include #include #include 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 }; //read through a file line by line call the callback with every line (without \n or \r) return true on sccess or false on error typedef std::function fileLineCallback; bool iterateFile(const std::string& filename, fileLineCallback clb, bool ignoreBlanks = true); bool iterateFile(std::istream& file, fileLineCallback clb, bool ignoreBlanks = true); //iterate over a folder typedef std::function fileNameFilter; typedef std::function fileCallback; template bool scan(const std::string& path, std::insert_iterator it, bool prefixdir = false, fileNameFilter fnf = fileNameFilter(nullptr)); bool scan(const std::string& path, fileCallback clb, bool prefixdir = false, fileNameFilter fnf = fileNameFilter(nullptr)); bool readFile(const std::string& name, std::ostream& output, unsigned int maxsize = 0); //reads file name and writes it line for line into output, it stops at maxsize (it might be a bit more, its not a hard limit - see it more as a hint), if maxsize is 0 it reads unlimited bool readFile(int fd, std::ostream& output, unsigned int maxsize = 0); bool copy(int fd_from, int fd_to); bool copy(const std::string& from, const std::string& to); std::string realPath(const std::string& str); }