PicoScenes API Docs
 
Loading...
Searching...
No Matches
SystemTools::File Namespace Reference

Functions

std::string getHomeDirectory ()
 Gets the home directory of the current user.
 
bool checkCommandExists (const std::string &command)
 Checks if a command exists in the system.
 
std::vector< struct timespec > getAccessChangeModifyTimeOfFile (const std::string &file)
 Gets the access, change, and modify times of a file.
 
bool touchFile (const std::string &file, std::optional< struct timespec > targetTimeOrNow)
 Updates the access and modification times of a file.
 
std::string getFileOwner (const std::string &filePath)
 Gets the owner of a file.
 
std::vector< uint8_t > readContentFromFile (const std::string &file)
 Reads the content of a file into a vector of bytes.
 
std::string readContentFromFileAsString (const std::string &file)
 Reads the content of a file into a string.
 
std::vector< std::string > readContentFromFileLineByLine (const std::string &filePath)
 Reads the content of a file line by line.
 
void writeContent2File (const std::string &file, const uint8_t *buffer, size_t bufferLength)
 Writes a buffer of bytes to a file.
 
void writeContent2File (const std::string &file, const std::string &content)
 Writes a string to a file.
 
bool removeFile (const std::string &filePath)
 Removes a file.
 
std::vector< fs::path > listFilesWithExtension (fs::path folderPath, std::string prefix="", std::string surfix="")
 Lists files in a directory with a specific prefix and suffix.
 
std::vector< fs::path > listFilesRecursivelyWithExtension (fs::path folderPath, std::string prefix="", std::string surfix="")
 Recursively lists files in a directory with a specific prefix and suffix.
 
template<typename ParseType >
ParseType readValueFromFilePath (const std::string &path)
 Reads a value from a file path.
 
template<typename ParseType >
int writeValue2FilePath (const std::string &path, const ParseType &value, const std::string &formatStr="{}")
 Writes a value to a file path.
 

Function Documentation

◆ checkCommandExists()

bool SystemTools::File::checkCommandExists ( const std::string &  command)

Checks if a command exists in the system.

Parameters
commandThe command to check.
Returns
True if the command exists, false otherwise.

◆ getAccessChangeModifyTimeOfFile()

std::vector< struct timespec > SystemTools::File::getAccessChangeModifyTimeOfFile ( const std::string &  file)

Gets the access, change, and modify times of a file.

Parameters
fileThe file path.
Returns
A vector of timespec structures representing the times.

◆ getFileOwner()

std::string SystemTools::File::getFileOwner ( const std::string &  filePath)

Gets the owner of a file.

Parameters
filePathThe file path.
Returns
The owner's name.

◆ getHomeDirectory()

std::string SystemTools::File::getHomeDirectory ( )

Gets the home directory of the current user.

Returns
The home directory path.

◆ listFilesRecursivelyWithExtension()

std::vector< fs::path > SystemTools::File::listFilesRecursivelyWithExtension ( fs::path  folderPath,
std::string  prefix = "",
std::string  surfix = "" 
)

Recursively lists files in a directory with a specific prefix and suffix.

Parameters
folderPathThe directory path.
prefixThe prefix to match.
surfixThe suffix to match.
Returns
A vector of paths matching the criteria.

◆ listFilesWithExtension()

std::vector< fs::path > SystemTools::File::listFilesWithExtension ( fs::path  folderPath,
std::string  prefix = "",
std::string  surfix = "" 
)

Lists files in a directory with a specific prefix and suffix.

Parameters
folderPathThe directory path.
prefixThe prefix to match.
surfixThe suffix to match.
Returns
A vector of paths matching the criteria.

◆ readContentFromFile()

std::vector< uint8_t > SystemTools::File::readContentFromFile ( const std::string &  file)

Reads the content of a file into a vector of bytes.

Parameters
fileThe file path.
Returns
A vector of bytes containing the file content.

◆ readContentFromFileAsString()

std::string SystemTools::File::readContentFromFileAsString ( const std::string &  file)

Reads the content of a file into a string.

Parameters
fileThe file path.
Returns
A string containing the file content.

◆ readContentFromFileLineByLine()

std::vector< std::string > SystemTools::File::readContentFromFileLineByLine ( const std::string &  filePath)

Reads the content of a file line by line.

Parameters
filePathThe file path.
Returns
A vector of strings, each representing a line in the file.

◆ readValueFromFilePath()

template<typename ParseType >
ParseType SystemTools::File::readValueFromFilePath ( const std::string &  path)

Reads a value from a file path.

Template Parameters
ParseTypeThe type to parse the value as.
Parameters
pathThe file path.
Returns
The parsed value.

Definition at line 218 of file SystemTools.hxx.

◆ removeFile()

bool SystemTools::File::removeFile ( const std::string &  filePath)

Removes a file.

Parameters
filePathThe file path.
Returns
True if the file was removed, false otherwise.

◆ touchFile()

bool SystemTools::File::touchFile ( const std::string &  file,
std::optional< struct timespec >  targetTimeOrNow 
)

Updates the access and modification times of a file.

Parameters
fileThe file path.
targetTimeOrNowOptional target time, or use current time if not specified.
Returns
True if successful, false otherwise.

◆ writeContent2File() [1/2]

void SystemTools::File::writeContent2File ( const std::string &  file,
const std::string &  content 
)

Writes a string to a file.

Parameters
fileThe file path.
contentThe string content to write.

◆ writeContent2File() [2/2]

void SystemTools::File::writeContent2File ( const std::string &  file,
const uint8_t *  buffer,
size_t  bufferLength 
)

Writes a buffer of bytes to a file.

Parameters
fileThe file path.
bufferThe buffer to write.
bufferLengthThe length of the buffer.

◆ writeValue2FilePath()

template<typename ParseType >
int SystemTools::File::writeValue2FilePath ( const std::string &  path,
const ParseType &  value,
const std::string &  formatStr = "{}" 
)

Writes a value to a file path.

Template Parameters
ParseTypeThe type of the value.
Parameters
pathThe file path.
valueThe value to write.
formatStrThe format string for the value.
Returns
Status code indicating success or failure.

Definition at line 244 of file SystemTools.hxx.