🟩 File System operations { exists, copy, delete } for { files and directories }
SaneCppFileSystem.h is a library enabling manipulation of files and directories.
| SC::FileSystem | Execute fs operations { exists, copy, delete } for { files and directories }. |
|---|---|
| Copy Files | |
| SC::FileSystem::copyFile | Copy a single file. |
| Delete Files | |
| SC::FileSystem::removeFile | Remove a single file. |
| SC::FileSystem::removeFileIfExists | Remove a single file, giving no error if it doesn't exist. |
| Copy Directories | |
| SC::FileSystem::copyDirectory | Copy a single directory. |
| Delete Directories | |
| SC::FileSystem::removeEmptyDirectory | Removes an empty directory. |
| SC::FileSystem::removeDirectoryRecursive | Remove single directory with its entire content (like posix rm -rf) |
| Create Directories | |
| SC::FileSystem::makeDirectory | Creates a new directory that does not already exist. |
| SC::FileSystem::makeDirectoryIfNotExists | Creates a new directory, if it doesn't already exists at the given path. |
| SC::FileSystem::makeDirectoryRecursive | Create a new directory, creating also intermediate non existing directories (like posix mkdir -p) |
| Create Links | |
| SC::FileSystem::createSymbolicLink | Creates a symbolic link at location linkFile pointing at sourceFileOrDirectory. |
| SC::FileSystem::createHardLink | Creates a hard link at location linkFile pointing at sourceFile. |
| Check Existence | |
| SC::FileSystem::exists | Check if a file or directory exists at a given path. |
| SC::FileSystem::existsAndIsFile | Check if a file exists at given path. |
| SC::FileSystem::existsAndIsDirectory | Check if a directory exists at given path. |
| SC::FileSystem::existsAndIsLink | Check if a link exists at given path. |
| SC::FileSystem::canAccess | Check whether the current process can access a path with the requested mode. |
| Rename files or directories | |
| SC::FileSystem::rename | Rename a file or directory. |
| Read / Change modification time | |
| SC::FileSystem::stat | Obtains richer metadata about a path, following symbolic links. |
| SC::FileSystem::lstat | Obtains richer metadata about a path without following symbolic links. |
| SC::FileSystem::getFileStat | Legacy convenience alias for stat(StringSpan, FileStat&) |
| SC::FileSystem::setLastModifiedTime | Change last modified time of a given file. |
| SC::FileSystem::readSymbolicLink | Reads the target path stored by a symbolic link. |
| SC::FileSystem::chmod | Change file permission bits for a path, following symbolic links. |
| SC::FileSystem::chown | Change owner and group for a path, following symbolic links. |
| SC::FileSystem::lchown | Change owner and group for a path without following symbolic links. |
| SC::FileSystem::lchmod | Change file permission bits for a symbolic link without following it. |
| Miscellaneous Classes | |
|---|---|
| SC::FileSystem::Operations | Low level filesystem API, requiring paths in native encoding (UTF-16 on Windows, UTF-8 elsewhere) |
| Get Executable / Application Path | |
| SC::FileSystem::Operations::getExecutablePath | |
| SC::FileSystem::Operations::getApplicationRootDirectory |
🟩 Usable
The library contains commonly used function including links, access checks and richer path metadata. Some lower level filesystem features are still missing, especially filesystem-level queries. SC::FileSystem::getFileTime and SC::FileSystem::setLastModifiedTime will probably be refactored in a future dedicated class for handling stat based operations.
Some relevant blog posts are:
SC::FileSystem allows all typical file operations ( exists | copy | delete | make files or directory). Some less used functions are SC::FileSystem::getFileTime and SC::FileSystem::setLastModifiedTime . The library also supports symlink and hardlink creation, reading symlink targets and checking path accessibility. The library doesn't allow reading or writing seeking inside a file, as that is domain of the File library. SC::FileSystem::init needs an absolute path to a directory and makes it a the base directory. All paths passed later on as arguments to all methods can be either absolute paths or relative. If they are relative, they will be interpreted as relative to the base directory and NOT current directory of the process. The class wants explicitly to make sure its behavior doesn't implicitly depend on current directory of process (unless it's passed explicitly to SC::FileSystem::init of course).
Use SC::Path from Strings library to parse and compose paths.
Copy a single file.
| source | Source file path |
| destination | Destination file path |
| copyFlags | Copy flags (overwrite, use clone api etc.) |
Example:
Copy a single directory.
| source | Source directory path |
| destination | Destination directory path |
| copyFlags | Copy flags (overwrite, use clone api etc.) |
Example:
Remove single directory with its entire content (like posix rm -rf)
| directory | Directory to remove |
Example:
Create a new directory, creating also intermediate non existing directories (like posix mkdir -p)
| directory | Path where to create such directory |
Check if a file exists at given path.
| file | File path to check |
true if a file exists at the given pathExample:
Check if a directory exists at given path.
| directory | Directory path to check |
true if a directory exists at the given path Rename a file or directory.
| path | The path to the file or directory to rename |
| newPath | The new path to the file or directory |
Example:
Creates a symbolic link at location linkFile pointing at sourceFileOrDirectory.
| sourceFileOrDirectory | The target of the link (can be a folder or directory) |
| linkFile | The location where the symbolic link will be created |
Creates a hard link at location linkFile pointing at sourceFile.
| sourceFile | The target file of the hard link |
| linkFile | The location where the hard link will be created |
Check if a link exists at given path.
| file | Link path to check |
true if a file exists at the given path Check whether the current process can access a path with the requested mode.
| fileOrDirectory | Path to check |
| accessMode | Requested access mode |
true if the requested access is allowed Obtains richer metadata about a path, following symbolic links.
| file | Path to the file of interest | |
| [out] | fileStat | Destination structure that will receive statistics about the file |
Obtains richer metadata about a path without following symbolic links.
| file | Path to the file of interest | |
| [out] | fileStat | Destination structure that will receive statistics about the file |
Reads the target path stored by a symbolic link.
| linkFile | Path to the symbolic link | |
| [out] | destination | Destination receiving the native-encoded target path |
Change file permission bits for a path, following symbolic links.
| path | Path to the file or directory of interest |
| mode | Platform-native numeric mode bits |
Change owner and group for a path, following symbolic links.
| path | Path to the file or directory of interest |
| uid | Platform-native numeric owner identifier |
| gid | Platform-native numeric group identifier |
Change owner and group for a path without following symbolic links.
| path | Path to the file or directory of interest |
| uid | Platform-native numeric owner identifier |
| gid | Platform-native numeric group identifier |
Change file permission bits for a symbolic link without following it.
| path | Path to the symbolic link of interest |
| mode | Platform-native numeric mode bits |
Writes a block of memory to a file.
| file | Path to the file that is meant to be written |
| data | Block of memory to write |
Example:
Read contents of a file into a String or Buffer.
| [in] | file | Path to the file to read |
| [out] | data | Destination String or Buffer that will receive file contents |
🟦 Complete Features:
statfs| Type | Lines Of Code | Comments | Sum |
|---|---|---|---|
| Headers | 117 | 232 | 349 |
| Sources | 1408 | 230 | 1638 |
| Sum | 1525 | 462 | 1987 |