Hymn to Beauty
C++ 3D Engine
FileSystem Namespace Reference

Functionality to interact with the file system. More...

Functions

bool FileExists (const char *filename)
 Check if a file exists. More...
 
void Copy (const char *source, const char *destination)
 Copy a file. More...
 
void CreateDirectory (const char *filename)
 Create a directory if it does not already exist. More...
 
bool DeleteDirectory (const char *filename)
 Delete a directory if it is empty. More...
 
std::vector< std::string > DirectoryContents (const std::string &directoryName, unsigned int type=FILE|DIRECTORY)
 Get all the contents of a directory. More...
 
std::string DataPath (const char *appName)
 Get save path for application data folder. More...
 
std::string DataPath (const char *appName, const char *filename)
 Get save path for application data. More...
 
std::string GetParentDirectory (const std::string &path)
 Get the parent directory of a path. More...
 
std::string GetExtension (const std::string &filename)
 Get the extension part of a filename. More...
 
std::string GetName (const std::string &filepath)
 Get the name of the file without the extension. More...
 
std::string GetDirectory (const std::string &path)
 Get the directory part for a path (including the final delimiter). More...
 
void ExecuteProgram (const std::string &path, const std::string &arguments)
 Execute a program asynchronously. More...
 

Variables

const char DELIMITER = '/'
 Delimiter, '\' on Windows, '/' elsewhere. More...
 
const unsigned int FILE = 1
 A file. More...
 
const unsigned int DIRECTORY = 2
 A directory. More...
 

Detailed Description

Functionality to interact with the file system.

Function Documentation

◆ Copy()

void FileSystem::Copy ( const char *  source,
const char *  destination 
)

Copy a file.

Parameters
sourceSource to copy.
destinationDestination to copy to.

◆ CreateDirectory()

void FileSystem::CreateDirectory ( const char *  filename)

Create a directory if it does not already exist.

Permission for new directory is 0777 on Unix.

Parameters
filenameFilename (either absolute or relative) for the directory to create.

◆ DataPath() [1/2]

std::string FileSystem::DataPath ( const char *  appName)

Get save path for application data folder.

The application data folder is created if it does not already exist. On Windows, this is <User>\AppData\Roaming\<AppName>. On MacOS, this is ~/Library/Application Support/<AppName>. On Linux, this is ~/.local/share/<AppName>.

Parameters
appNameThe name of the app/game.
Returns
The path

◆ DataPath() [2/2]

std::string FileSystem::DataPath ( const char *  appName,
const char *  filename 
)

Get save path for application data.

The application data folder is created if it does not already exist. On Windows, this is <User>\AppData\Roaming\<AppName>\<Filename>. On MacOS, this is ~/Library/Application Support/<AppName>/<Filename>. On Linux, this is ~/.local/share/<AppName>/<Filename>.

Parameters
appNameThe name of the app/game.
filenameFilename, eg. "settings.ini".
Returns
The path

◆ DeleteDirectory()

bool FileSystem::DeleteDirectory ( const char *  filename)

Delete a directory if it is empty.

Parameters
filenameThe path of the directory to remove.
Returns
Whether the directory was deleted successfully.

◆ DirectoryContents()

std::vector< std::string > FileSystem::DirectoryContents ( const std::string &  directoryName,
unsigned int  type = FILE|DIRECTORY 
)

Get all the contents of a directory.

Parameters
directoryNamePath to the directory to scan.
typeType of content to get, FILE, DIRECTORY or both (use | to combine).
Returns
A list of all the files/directories in the directory.

◆ ExecuteProgram()

void FileSystem::ExecuteProgram ( const std::string &  path,
const std::string &  arguments 
)

Execute a program asynchronously.

Parameters
pathThe path to the program to execute.
argumentsThe arguments to the program.

◆ FileExists()

bool FileSystem::FileExists ( const char *  filename)

Check if a file exists.

Works for directories as well.

Parameters
filenameFilename (either relative or absolute) to check.
Returns
Whether the file exists

◆ GetDirectory()

std::string FileSystem::GetDirectory ( const std::string &  path)

Get the directory part for a path (including the final delimiter).

Parameters
pathThe path to get the directory part of.
Returns
The directory path of the path.

◆ GetExtension()

std::string FileSystem::GetExtension ( const std::string &  filename)

Get the extension part of a filename.

Parameters
filenameThe filename to check.
Returns
The extension part of the filename, converted to lower case.

◆ GetName()

std::string FileSystem::GetName ( const std::string &  filepath)

Get the name of the file without the extension.

Parameters
filepathThe datapath to the file.
Returns
The name of the file without extension.

◆ GetParentDirectory()

std::string FileSystem::GetParentDirectory ( const std::string &  path)

Get the parent directory of a path.

Parameters
pathAbsolute path to get the parent directory of.
Returns
Path of the parent directory.

Variable Documentation

◆ DELIMITER

const char FileSystem::DELIMITER = '/'

Delimiter, '\' on Windows, '/' elsewhere.

◆ DIRECTORY

const unsigned int FileSystem::DIRECTORY = 2

A directory.

◆ FILE

const unsigned int FileSystem::FILE = 1

A file.