50template bool exists<verbose::d>(
const std::string &,
error_t &);
52template bool dir_exists_is<verbose::d>(
const std::string &,
error_t &);
58 std::filesystem::create_directories( path, ec );
59 if( ec.value() != 0 && ec.value() != EEXIST )
72std::string
pathStem(
const std::string &fname )
74 std::filesystem::path p( fname );
75 return p.stem().string();
80 std::filesystem::path p( fname );
81 return p.filename().string();
86 std::filesystem::path p( fname );
87 return p.parent_path().string();
94error_t getFileNames<verbose::d>( std::vector<std::string> &fileNames,
95 const std::string &directory,
96 const std::string &prefix,
97 const std::string &substr,
98 const std::string &extension );
104 std::string dir, base, ext;
106 std::filesystem::path p = fname;
107 dir = p.parent_path().string();
108 base = p.stem().string();
109 ext = p.extension().string();
111 return dir +
'/' + prepend + base + append + ext;
125getSequentialFilename(
const std::string &basename,
const std::string &extension,
const int startat,
const int ndigit )
129 int maxdig = pow( 10, ndigit );
132 snprintf( formstr,
sizeof( formstr ),
"%%0%dd", ndigit );
137 std::stringstream outn;
139 snprintf( digstr,
sizeof( digstr ), formstr, i );
145 while( std::filesystem::exists( outn.str() ) && i < maxdig )
150 snprintf( digstr,
sizeof( digstr ), formstr, i );
170 if( ( fstat( fd, &stbuf ) != 0 ) || ( !S_ISREG( stbuf.st_mode ) ) )
175 return stbuf.st_size;
Declarations of utilities for working with files.
error_t
The mxlib error codes.
static constexpr error_t errno2error_t(const int &err)
Convert an errno code to error_t.
@ noerror
No error has occurred.
@ filesystem
A general filesystem error occurred.
@ error
A general error has occurred.
std::string fileNamePrepend(const std::string &fname, const std::string &prepend)
Prepend strings to a file name, leaving the directory and extension unaltered.
std::string getSequentialFilename(const std::string &basename, const std::string &extension="", const int startat=0, int ndigit=4)
Get the next file in a numbered sequence.
std::string fileNamePrependAppend(const std::string &fname, const std::string &prepend, const std::string &append)
Prepend and/or append strings to a file name, leaving the directory and extension unaltered.
std::string fileNameAppend(const std::string &fname, const std::string &append)
Append a string to a file name, leaving the directory and extension unaltered.
error_t createDirectories(const std::string &path)
Create a directory or directories.
std::string parentPath(const std::string &fname)
Get the parent path from a filename.
std::string pathStem(const std::string &fname)
Get the stem of the filename.
off_t fileSize(int fd)
Get the size in bytes of a file.
std::string pathFilename(const std::string &fname)
Get the base filename.