RADLib
RADical C++ application framework
RADCore::FileSystem Namespace Reference

Filesystem helper namespace for paths, standard locations, MIME guesses, and text files. More...

Classes

struct  DirectoryEntry
 Directory listing entry with basic metadata. More...
 

Enumerations

enum class  StandardPath {
  Home , Desktop , Documents , Downloads ,
  Config , Data , Cache , Temp ,
  Executable , Current
}
 Standard platform path categories. More...
 
enum class  DirectoryEntryType { Unknown , File , Directory , Symlink }
 Directory entry type. More...
 

Functions

bool exists (const std::string &path)
 Returns true when path exists. More...
 
bool isFile (const std::string &path)
 Returns true when path is a regular file. More...
 
bool isDirectory (const std::string &path)
 Returns true when path is a directory. More...
 
bool createDirectories (const std::string &path)
 Creates path and missing parents. More...
 
bool remove (const std::string &path)
 Removes file or directory path. More...
 
bool copyFile (const std::string &source, const std::string &destination, bool overwrite=true)
 Copies a file from source to destination. More...
 
std::string currentPath ()
 Returns current working directory. More...
 
std::string tempDirectoryPath ()
 Returns system temporary directory. More...
 
std::string standardPath (StandardPath path)
 Returns a standard platform path. More...
 
std::string fileName (const std::string &path)
 Returns filename component of path. More...
 
std::string extension (const std::string &path)
 Returns extension component of path. More...
 
std::string parentPath (const std::string &path)
 Returns parent directory path. More...
 
std::vector< DirectoryEntrylistEntries (const std::string &path, bool recursive=false)
 Lists directory entries, recursively when requested. More...
 
std::vector< std::string > listDirectory (const std::string &path)
 Lists child paths in a directory. More...
 
std::string mimeTypeForFile (const std::string &path)
 Guesses MIME type from file contents or extension. More...
 
std::optional< std::string > readTextFile (const std::string &path)
 Reads a UTF-8/text file into a string. More...
 
bool writeTextFile (const std::string &path, const std::string &text)
 Writes text to a file. More...
 

Detailed Description

Filesystem helper namespace for paths, standard locations, MIME guesses, and text files.

Enumeration Type Documentation

◆ DirectoryEntryType

Directory entry type.

Enumerator
Unknown 

Type could not be determined.

File 

Regular file.

Directory 

Directory.

Symlink 

Symbolic link.

◆ StandardPath

Standard platform path categories.

Enumerator
Home 

User home directory.

Desktop 

Desktop directory.

Documents 

Documents directory.

Downloads 

Downloads directory.

Config 

Configuration directory.

Data 

Application data directory.

Cache 

Cache directory.

Temp 

Temporary directory.

Executable 

Running executable path.

Current 

Current working directory.

Function Documentation

◆ copyFile()

bool RADCore::FileSystem::copyFile ( const std::string &  source,
const std::string &  destination,
bool  overwrite = true 
)

Copies a file from source to destination.

◆ createDirectories()

bool RADCore::FileSystem::createDirectories ( const std::string &  path)

Creates path and missing parents.

◆ currentPath()

std::string RADCore::FileSystem::currentPath ( )

Returns current working directory.

◆ exists()

bool RADCore::FileSystem::exists ( const std::string &  path)

Returns true when path exists.

◆ extension()

std::string RADCore::FileSystem::extension ( const std::string &  path)

Returns extension component of path.

◆ fileName()

std::string RADCore::FileSystem::fileName ( const std::string &  path)

Returns filename component of path.

◆ isDirectory()

bool RADCore::FileSystem::isDirectory ( const std::string &  path)

Returns true when path is a directory.

◆ isFile()

bool RADCore::FileSystem::isFile ( const std::string &  path)

Returns true when path is a regular file.

◆ listDirectory()

std::vector<std::string> RADCore::FileSystem::listDirectory ( const std::string &  path)

Lists child paths in a directory.

◆ listEntries()

std::vector<DirectoryEntry> RADCore::FileSystem::listEntries ( const std::string &  path,
bool  recursive = false 
)

Lists directory entries, recursively when requested.

◆ mimeTypeForFile()

std::string RADCore::FileSystem::mimeTypeForFile ( const std::string &  path)

Guesses MIME type from file contents or extension.

◆ parentPath()

std::string RADCore::FileSystem::parentPath ( const std::string &  path)

Returns parent directory path.

◆ readTextFile()

std::optional<std::string> RADCore::FileSystem::readTextFile ( const std::string &  path)

Reads a UTF-8/text file into a string.

◆ remove()

bool RADCore::FileSystem::remove ( const std::string &  path)

Removes file or directory path.

◆ standardPath()

std::string RADCore::FileSystem::standardPath ( StandardPath  path)

Returns a standard platform path.

◆ tempDirectoryPath()

std::string RADCore::FileSystem::tempDirectoryPath ( )

Returns system temporary directory.

◆ writeTextFile()

bool RADCore::FileSystem::writeTextFile ( const std::string &  path,
const std::string &  text 
)

Writes text to a file.