BoosterSeat  0.1
A C++ library that includes common utilities that are used in other projects.
bst::filesystem Namespace Reference

Namespaces

 units
 

Functions

void appendToFile (const std::string &file_path, const std::string &content, const bool new_line_after=true)
 Append a string to a file. More...
 
void copyFile (const std::string &source_path, const std::string &destination_path, bool overwrite=false)
 Move a file from one location to another. More...
 
void createDirectory (const std::string &directory_path)
 Create a Directory at the specified path. More...
 
void createFile (const std::string &file_path)
 Create a File. More...
 
void deleteFile (const std::string &file_path)
 Delete a file. More...
 
bool doesDirectoryExist (const std::string &directory_path)
 Returns a boolean indicating whether or not the directory exists. More...
 
bool doesFileExist (const std::string &file_path)
 Returns a boolean indicating whether or not the file exists. If it's a directory an exception will be thrown. More...
 
double getDirectorySize (const std::string &directory_path, units::Size unit=units::Size::BYTES)
 Get the size of a directory. Only includes regular files. More...
 
std::string getFileName (const std::string &file_path)
 Get the File Name from a path. Does not need to exist. More...
 
double getFileSize (const std::string &file_path, units::Size size_unit=units::Size::BYTES)
 Get the size of a file. More...
 
uintmax_t getFileSizeBytes (const std::string &file_path)
 Get the size of a file. More...
 
bool hasReadPermission (const std::string &path)
 If a program has read permissions to a file or directory, it will return true. Otherwise, it will return false. More...
 
bool hasWritePermission (const std::string &path)
 If a program has write permissions to a file or directory, it will return true. Otherwise, it will return false. More...
 
void moveFile (const std::string &source_path, const std::string &destination_path, bool overwrite=false)
 Move a file from one location to another. More...
 
void overwriteFile (const std::string &file_path, const std::string &content)
 Overwrite a files with a string. More...
 

Function Documentation

◆ doesFileExist()

bool bst::filesystem::doesFileExist ( const std::string &  file_path)

Returns a boolean indicating whether or not the file exists. If it's a directory an exception will be thrown.

Parameters
file_pathThe path to the file.
Returns
true - The file exists, false otherwise.
Exceptions
BoosterSeatException- If the path is a directory. error.

Referenced by TEST().

Here is the caller graph for this function:

◆ createFile()

void bst::filesystem::createFile ( const std::string &  file_path)

Create a File.

Parameters
file_pathThe path to the file.
Exceptions
BoosterSeatException- If the file already exists or cannot be created.

Referenced by TEST().

Here is the caller graph for this function:

◆ appendToFile()

void bst::filesystem::appendToFile ( const std::string &  file_path,
const std::string &  content,
const bool  new_line_after = true 
)

Append a string to a file.

Parameters
file_path- The path to the file.
content- A string to append to the file.
new_line_after- default true - If true, a new line will be added after the data.
Exceptions
BoosterSeatException- If the file already exists, the program does not have write permissions, or the file cannot be opened.

Referenced by TEST().

Here is the caller graph for this function:

◆ overwriteFile()

void bst::filesystem::overwriteFile ( const std::string &  file_path,
const std::string &  content 
)

Overwrite a files with a string.

Parameters
file_path- The path to the file.
content- A string to overwrite the file with.
Exceptions
BoosterSeatException- If the file already exists, the program does not have write permissions, or the file cannot be opened.

Referenced by TEST().

Here is the caller graph for this function:

◆ getFileSize()

double bst::filesystem::getFileSize ( const std::string &  file_path,
units::Size  size_unit = units::Size::BYTES 
)

Get the size of a file.

Parameters
file_path- The path to the file
unit- The unit to return the size in. (default: bytes)
Returns
double - The size of the file in the specified unit.
Exceptions
BoosterSeatException- If the path is not a regular file, the size cannot be determined, or the file does not exist.

Referenced by TEST().

Here is the caller graph for this function:

◆ getFileSizeBytes()

uintmax_t bst::filesystem::getFileSizeBytes ( const std::string &  file_path)

Get the size of a file.

Parameters
file_path- The path to the file
unit- The unit to return the size in. (default: bytes)
Returns
double - The size of the file in the specified unit.
Exceptions
BoosterSeatException- If the path is not a regular file, the size cannot be determined, or the file does not exist.

Referenced by TEST().

Here is the caller graph for this function:

◆ deleteFile()

void bst::filesystem::deleteFile ( const std::string &  file_path)

Delete a file.

Parameters
file_path- The path to the file.
Exceptions
BoosterSeatException- If the file does not exist, the program does not have write permissions, or the file cannot be deleted.

Referenced by TEST().

Here is the caller graph for this function:

◆ doesDirectoryExist()

bool bst::filesystem::doesDirectoryExist ( const std::string &  directory_path)

Returns a boolean indicating whether or not the directory exists.

Parameters
directory_path- The path to the directory.
Returns
true - The directory exists.
false - The directory does not exist in the path.
Exceptions
BoosterSeatException- If the path is a file, or the program does not have permissions to read the size of the directory.

Referenced by TEST().

Here is the caller graph for this function:

◆ createDirectory()

void bst::filesystem::createDirectory ( const std::string &  directory_path)

Create a Directory at the specified path.

Parameters
directory_path- The path to the directory, including the directory name. (e.g. /home/user/MyNewDirectory)
Exceptions
BoosterSeatException- If the directory already exists, the program does not have write permissions, or the directory cannot be created.

Referenced by TEST().

Here is the caller graph for this function:

◆ getDirectorySize()

double bst::filesystem::getDirectorySize ( const std::string &  directory_path,
units::Size  unit = units::Size::BYTES 
)

Get the size of a directory. Only includes regular files.

Parameters
directory_path- The path to the directory
unit- The unit to return the size in. (default: bytes)
recursive- If true, the size of all subdirectories will be included.
Returns
double - The size of the directory in the specified unit.
Exceptions
BoosterSeatException- If the path is not a directory, the size cannot be determined, or the directory does not exist.

Referenced by TEST().

Here is the caller graph for this function:

◆ hasWritePermission()

bool bst::filesystem::hasWritePermission ( const std::string &  path)

If a program has write permissions to a file or directory, it will return true. Otherwise, it will return false.

Note
Only works on Linux systems, currently does not throw an exception if the path does not exist.
Parameters
path- The path to the file or directory.
Returns
true - The program has write permissions.
false - The program does not have write permissions.

Referenced by TEST().

Here is the caller graph for this function:

◆ hasReadPermission()

bool bst::filesystem::hasReadPermission ( const std::string &  path)

If a program has read permissions to a file or directory, it will return true. Otherwise, it will return false.

Note
Only works on Linux systems, currently does not throw an exception if the path does not exist.
Parameters
path- The path to the file or directory.
Returns
true - The program has read permissions.
false - The program does not have read permissions.

Referenced by TEST().

Here is the caller graph for this function:

◆ moveFile()

void bst::filesystem::moveFile ( const std::string &  source_path,
const std::string &  destination_path,
bool  overwrite = false 
)

Move a file from one location to another.

Parameters
source_path- The path to the file to move.
destination_path- The path to move the file to.

Referenced by TEST().

Here is the caller graph for this function:

◆ copyFile()

void bst::filesystem::copyFile ( const std::string &  source_path,
const std::string &  destination_path,
bool  overwrite = false 
)

Move a file from one location to another.

Parameters
source_path- The path to the file to move.
destination_path- The path to move the file to.
overwrite- If true, the destination file will be overwritten if it exists.
Exceptions
BoosterSeatException- If the source file does not exist.
BoosterSeatException- If the destination file already exists and overwrite is false.

Referenced by TEST().

Here is the caller graph for this function:

◆ getFileName()

std::string bst::filesystem::getFileName ( const std::string &  file_path)

Get the File Name from a path. Does not need to exist.

Parameters
file_path- The path to the file.
Returns
std::string - The file name.

Referenced by TEST().

Here is the caller graph for this function: