Base module

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)

Defined in src/base/include/icy/filesystem.h:38

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

Returns

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

Parameters

ParameterTypeDescription
pathstd::string_viewFilesystem path to parse.

basename

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

Defined in src/base/include/icy/filesystem.h:43

Returns the file name without its extension.

Returns

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

Parameters

ParameterTypeDescription
pathstd::string_viewFilesystem path to parse.

dirname

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

Defined in src/base/include/icy/filesystem.h:48

Returns the directory part of the path.

Returns

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

Parameters

ParameterTypeDescription
pathstd::string_viewFilesystem path to parse.

extname

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

Defined in src/base/include/icy/filesystem.h:54

Returns the file extension part of the path.

Returns

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

Parameters

ParameterTypeDescription
pathstd::string_viewFilesystem path to parse.
includeDotboolIf true (default), includes the leading dot (e.g. ".txt"); if false, the dot is stripped.

exists

bool exists(std::string_view path)

Defined in src/base/include/icy/filesystem.h:59

Returns true if the file or directory exists.

Returns

True if the path exists on the filesystem.

Parameters

ParameterTypeDescription
pathstd::string_viewPath to check.

isdir

bool isdir(std::string_view path)

Defined in src/base/include/icy/filesystem.h:64

Returns true if the path refers to a directory.

Returns

True if the path exists and is a directory.

Parameters

ParameterTypeDescription
pathstd::string_viewPath to check.

filesize

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

Defined in src/base/include/icy/filesystem.h:69

Returns the size in bytes of the given file.

Returns

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

Parameters

ParameterTypeDescription
pathstd::string_viewPath to the file.

readdir

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

Defined in src/base/include/icy/filesystem.h:74

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

Parameters

ParameterTypeDescription
pathstd::string_viewPath to the directory to read.
resstd::vector< std::string > &Vector to receive the list of entry names.

mkdir

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

Defined in src/base/include/icy/filesystem.h:79

Creates a single directory.

Parameters

ParameterTypeDescription
pathstd::string_viewPath of the directory to create.
modeintPermission bits (default: 0755). Ignored on Windows.

mkdirr

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

Defined in src/base/include/icy/filesystem.h:84

Creates a directory and all missing parent directories.

Parameters

ParameterTypeDescription
pathstd::string_viewPath of the directory hierarchy to create.
modeintPermission bits (default: 0755). Ignored on Windows.

rmdir

void rmdir(std::string_view path)

Defined in src/base/include/icy/filesystem.h:88

Removes an empty directory.

Parameters

ParameterTypeDescription
pathstd::string_viewPath of the directory to remove.

void unlink(std::string_view path)

Defined in src/base/include/icy/filesystem.h:92

Deletes a file.

Parameters

ParameterTypeDescription
pathstd::string_viewPath of the file to delete.

rename

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

Defined in src/base/include/icy/filesystem.h:97

Renames or moves the given file to the target path.

Parameters

ParameterTypeDescription
pathstd::string_viewSource file path.
targetstd::string_viewDestination file path.

addsep

void addsep(std::string & path)

Defined in src/base/include/icy/filesystem.h:101

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

Parameters

ParameterTypeDescription
pathstd::string &Path string to modify in place.

addnode

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

Defined in src/base/include/icy/filesystem.h:106

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

Parameters

ParameterTypeDescription
pathstd::string &Base path string to modify in place.
nodestd::string_viewDirectory or file name component to append.

makePath

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

Defined in src/base/include/icy/filesystem.h:112

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

Returns

Joined path string.

Parameters

ParameterTypeDescription
basestd::string_viewBase directory path.
nodestd::string_viewDirectory or file name component to append.

normalize

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

Defined in src/base/include/icy/filesystem.h:118

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

Returns

Normalized path string.

Parameters

ParameterTypeDescription
pathstd::string_viewPath string to normalize.

transcode

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

Defined in src/base/include/icy/filesystem.h:125

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.

Returns

Transcoded path string.

Parameters

ParameterTypeDescription
pathstd::string_viewPath string to transcode.

savefile

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

Defined in src/base/include/icy/filesystem.h:133

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

Returns

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

Parameters

ParameterTypeDescription
pathstd::string_viewDestination file path. Parent directories must already exist.
dataconst char *Pointer to the data to write.
sizesize_tNumber of bytes to write.
whinyboolIf true, throws a std::runtime_error on failure instead of returning 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

Defined in src/base/include/icy/filesystem.h:29

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


delimiter

const char delimiter

Defined in src/base/include/icy/filesystem.h:33

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