Base module

fs

Cross-platform filesystem path and file helpers.

fs

Cross-platform filesystem path and file helpers.

Functions

ReturnNameDescription
std::stringfilenameReturns the file name and extension part of the given path.
std::stringbasenameReturns the file name without its extension.
std::stringdirnameReturns the directory part of the path.
std::stringextnameReturns the file extension part of the path.
boolexistsReturns true if the file or directory exists.
boolisdirReturns true if the path refers to a directory.
std::int64_tfilesizeReturns the size in bytes of the given file.
voidreaddirPopulates res with the names of all entries in the given directory.
voidmkdirCreates a single directory.
voidmkdirrCreates a directory and all missing parent directories.
voidrmdirRemoves an empty directory.
voidunlinkDeletes a file.
voidrenameRenames or moves the given file to the target path.
voidaddsepAppends the platform-specific path separator to path if not already present.
voidaddnodeAppends a path node to path, inserting a separator if necessary.
std::stringmakePathJoins a base path and a node component into a single path string.
std::stringnormalizeNormalizes a path by resolving . and .. segments and converting separators to the native platform style.
std::stringtranscodeTranscodes a path to the native platform format. On Windows with ICY_UNICODE defined, converts to the Windows-native wide-to-narrow format. On other platforms, returns the path unchanged.
boolsavefileWrites size bytes from data to the file at path, creating or overwriting it.

filename

std::string filename(std::string_view path)

Returns the file name and extension part of the given path.

Parameters

  • path Filesystem path to parse.

Returns

Filename component including extension (e.g. "file.txt").


basename

std::string basename(std::string_view path)

Returns the file name without its extension.

Parameters

  • path Filesystem path to parse.

Returns

Filename without the extension (e.g. "file").


dirname

std::string dirname(std::string_view path)

Returns the directory part of the path.

Parameters

  • path Filesystem path to parse.

Returns

Directory component including trailing separator (e.g. "/usr/local/").


extname

std::string extname(std::string_view path, bool includeDot)

Returns the file extension part of the path.

Parameters

  • path Filesystem path to parse.

  • includeDot If true (default), includes the leading dot (e.g. ".txt"); if false, the dot is stripped.

Returns

Extension string, or empty if the path has no extension.


exists

bool exists(std::string_view path)

Returns true if the file or directory exists.

Parameters

  • path Path to check.

Returns

True if the path exists on the filesystem.


isdir

bool isdir(std::string_view path)

Returns true if the path refers to a directory.

Parameters

  • path Path to check.

Returns

True if the path exists and is a directory.


filesize

std::int64_t filesize(std::string_view path)

Returns the size in bytes of the given file.

Parameters

  • path Path to the file.

Returns

File size in bytes, or -1 if the file does not exist.


readdir

void readdir(std::string_view path, std::vector< std::string > & res)

Populates res with the names of all entries in the given directory.

Parameters

  • path Path to the directory to read.

  • res Vector to receive the list of entry names.


mkdir

void mkdir(std::string_view path, int mode)

Creates a single directory.

Parameters

  • path Path of the directory to create.

  • mode Permission bits (default: 0755). Ignored on Windows.


mkdirr

void mkdirr(std::string_view path, int mode)

Creates a directory and all missing parent directories.

Parameters

  • path Path of the directory hierarchy to create.

  • mode Permission bits (default: 0755). Ignored on Windows.


rmdir

void rmdir(std::string_view path)

Removes an empty directory.

Parameters

  • path Path of the directory to remove.

void unlink(std::string_view path)

Deletes a file.

Parameters

  • path Path of the file to delete.

rename

void rename(std::string_view path, std::string_view target)

Renames or moves the given file to the target path.

Parameters

  • path Source file path.

  • target Destination file path.


addsep

void addsep(std::string & path)

Appends the platform-specific path separator to path if not already present.

Parameters

  • path Path string to modify in place.

addnode

void addnode(std::string & path, std::string_view node)

Appends a path node to path, inserting a separator if necessary.

Parameters

  • path Base path string to modify in place.

  • node Directory or file name component to append.


makePath

std::string makePath(std::string_view base, std::string_view node)

Joins a base path and a node component into a single path string.

Parameters

  • base Base directory path.

  • node Directory or file name component to append.

Returns

Joined path string.


normalize

std::string normalize(std::string_view path)

Normalizes a path by resolving . and .. segments and converting separators to the native platform style.

Parameters

  • path Path string to normalize.

Returns

Normalized path string.


transcode

std::string transcode(std::string_view path)

Transcodes a path to the native platform format. On Windows with ICY_UNICODE defined, converts to the Windows-native wide-to-narrow format. On other platforms, returns the path unchanged.

Parameters

  • path Path string to transcode.

Returns

Transcoded path string.


savefile

bool savefile(std::string_view path, const char * data, size_t size, bool whiny)

Writes size bytes from data to the file at path, creating or overwriting it.

Parameters

  • path Destination file path. Parent directories must already exist.

  • data Pointer to the data to write.

  • size Number of bytes to write.

  • whiny If true, throws a std::runtime_error on failure instead of returning false.

Returns

True on success, false on failure (when whiny is false).

Variables

ReturnNameDescription
const char *separatorThe platform specific path separator string: "/" on unix and "\" on windows.
const chardelimiterThe platform specific path separator character: '/' on unix and '' on windows.

separator

const char * separator

The platform specific path separator string: "/" on unix and "\" on windows.


delimiter

const char delimiter

The platform specific path separator character: '/' on unix and '' on windows.