Documentation for OpenFLUID 2.2.0
openfluid::tools::Filesystem Class Reference

#include <tools/Filesystem.hpp>

Public Member Functions

 Filesystem ()=delete
 

Static Public Member Functions

constexpr static char pathsListSeparator () noexcept
 
constexpr static char pathSeparator () noexcept
 
static std::string joinPath (const std::vector< std::string > &PathParts)
 
static std::string homePath ()
 
static std::string tempPath ()
 
static std::string filename (const std::string &Path)
 
static std::string dirname (const std::string &Path)
 
static std::string basename (const std::string &Path)
 
static std::string minimalBasename (const std::string &Path)
 
static std::string extension (const std::string &Path)
 
static std::string completeExtension (const std::string &Path)
 
static std::string currentPath ()
 
static std::string absolutePath (const std::string &Path)
 
static std::string makeUniqueSubdirectory (const std::string &Path, const std::string &SubdirName)
 
static std::string makeUniqueFile (const std::string &Path, const std::string &FileName)
 
static std::string readFile (const openfluid::tools::FilesystemPath &FileObj)
 
static void writeFile (const std::string &Content, const openfluid::tools::FilesystemPath &FileObj)
 
static void appendToFile (const std::string &Content, const openfluid::tools::FilesystemPath &FileObj)
 
static bool copyFile (const std::string &SrcPath, const std::string &DestPath)
 
static bool renameFile (const std::string &OriginalPath, const std::string &NewPath)
 
static bool copyDirectory (const std::string &SrcPath, const std::string &DestPath, bool WithBaseDir=false, bool RemoveExisting=false)
 
static bool copyDirectoryContent (const std::filesystem::path &SrcPath, const std::filesystem::path &DestPath)
 
static bool emptyDirectory (const std::string &Path, const std::vector< std::string > &PathsToExlude={})
 
static std::vector< std::string > findFiles (const std::string &Path, bool WithPath=false, const std::string &Pattern="")
 
static std::vector< std::string > findDirectories (const std::string &Path, bool WithPath=false, const std::string &Pattern="")
 
static std::vector< std::string > findFilesByExtension (const std::string &Path, const std::string &Ext, bool WithPath=false, bool ExtIncludeDot=false)
 
static std::vector< std::string > findFilesBySuffixAndExtension (const std::string &Path, const std::string &Suffix, const std::string &Ext, bool WithPath=false, bool ExtIncludeDot=false)
 

Constructor & Destructor Documentation

◆ Filesystem()

openfluid::tools::Filesystem::Filesystem ( )
delete

Member Function Documentation

◆ absolutePath()

static std::string openfluid::tools::Filesystem::absolutePath ( const std::string &  Path)
static

Returns the absolute path of the given path. If the given path is already an absolute path, it is returned as-is.

Parameters
[in]Paththe path to make absolute
Returns
the absolute path

◆ appendToFile()

static void openfluid::tools::Filesystem::appendToFile ( const std::string &  Content,
const openfluid::tools::FilesystemPath FileObj 
)
static

Appends content on a new line into a file

Parameters
[in]Contentthe content to append
[in]FileObjthe given path for the file

◆ basename()

static std::string openfluid::tools::Filesystem::basename ( const std::string &  Path)
static

◆ completeExtension()

static std::string openfluid::tools::Filesystem::completeExtension ( const std::string &  Path)
static

◆ copyDirectory()

static bool openfluid::tools::Filesystem::copyDirectory ( const std::string &  SrcPath,
const std::string &  DestPath,
bool  WithBaseDir = false,
bool  RemoveExisting = false 
)
static

Recursively copies a directory from source to destination.

Parameters
[in]SrcPaththe source path
[in]DestPaththe destination path
[in]WithBaseDirif true, the source directory is created in the destination dir as an intermdiate directory (e.g. if the content of /my/path/first is copied into /my/path/second, the content will actually be copied into /my/path/second/first)
[in]RemoveExistingif true, the destination directory is deleted if it already exists
Returns
true if the directory was successfully copied, false otherwise

◆ copyDirectoryContent()

static bool openfluid::tools::Filesystem::copyDirectoryContent ( const std::filesystem::path &  SrcPath,
const std::filesystem::path &  DestPath 
)
static

Recursively copies content of a directory from source to destination, handling windows bug with regular dir copy.

Parameters
[in]SrcPaththe source path
[in]DestPaththe destination path
Returns
true if the directory was successfully copied, false otherwise

◆ copyFile()

static bool openfluid::tools::Filesystem::copyFile ( const std::string &  SrcPath,
const std::string &  DestPath 
)
static

Copies a file from source to destination.

Parameters
[in]SrcPaththe source path
[in]DestPaththe destination path
Returns
true if the file was successfully copied, false otherwise

◆ currentPath()

static std::string openfluid::tools::Filesystem::currentPath ( )
static

Returns the current path

Returns
the current path

◆ dirname()

static std::string openfluid::tools::Filesystem::dirname ( const std::string &  Path)
static

◆ emptyDirectory()

static bool openfluid::tools::Filesystem::emptyDirectory ( const std::string &  Path,
const std::vector< std::string > &  PathsToExlude = {} 
)
static

Recursively removes all files and directories contained in the given directory. It deletes the directory and recreates it.

Parameters
[in]Paththe directory to empty
[in]PathsToExludePaths that are not deleted.
Returns
true if successful

◆ extension()

static std::string openfluid::tools::Filesystem::extension ( const std::string &  Path)
static

◆ filename()

static std::string openfluid::tools::Filesystem::filename ( const std::string &  Path)
static

◆ findDirectories()

static std::vector<std::string> openfluid::tools::Filesystem::findDirectories ( const std::string &  Path,
bool  WithPath = false,
const std::string &  Pattern = "" 
)
static

Gets the list of directories found in the specified directory

Parameters
[in]Paththe directory to explore
[in]WithPathreturn full path if true, directory name only otherwise
[in]Patternan optional pattern to filter the directories to find

◆ findFiles()

static std::vector<std::string> openfluid::tools::Filesystem::findFiles ( const std::string &  Path,
bool  WithPath = false,
const std::string &  Pattern = "" 
)
static

Gets the list of files found in the specified directory

Parameters
[in]Paththe directory to explore
[in]WithPathreturn full path if true, directory name only otherwise
[in]Patternan optional pattern to filter the files to find

◆ findFilesByExtension()

static std::vector<std::string> openfluid::tools::Filesystem::findFilesByExtension ( const std::string &  Path,
const std::string &  Ext,
bool  WithPath = false,
bool  ExtIncludeDot = false 
)
static

Gets the list of files with specified extension contained in the specified directory

Parameters
[in]Paththe directory to explore
[in]Extthe file extension
[in]WithPathreturn full path with file name if true, file name only otherwise
[in]ExtIncludeDotif true, the given extension through Ext parameter is suffixed by a dot

◆ findFilesBySuffixAndExtension()

static std::vector<std::string> openfluid::tools::Filesystem::findFilesBySuffixAndExtension ( const std::string &  Path,
const std::string &  Suffix,
const std::string &  Ext,
bool  WithPath = false,
bool  ExtIncludeDot = false 
)
static

Get list of files with specified extension contained in the specified dir

Parameters
[in]Paththe directory to explore
[in]Extthe file extension
[in]Suffixthe file suffix
[in]WithPathreturn full path with file name if true, file name only otherwise
[in]ExtIncludeDotif true, the given extension through Ext parameter is suffixed by a dot

◆ homePath()

static std::string openfluid::tools::Filesystem::homePath ( )
static

Returns the user home path (e.g. '/home/username' on Linux, 'C:/Users/username' on Windows, ...)

Returns
the user home path

◆ joinPath()

static std::string openfluid::tools::Filesystem::joinPath ( const std::vector< std::string > &  PathParts)
static

Returns a joined path string from a vector of path parts, using the '/' separator

Parameters
[in]PathPartsa vector of path parts
Returns
the joined path
std::string Path;
Path = openfluid::tools::Filesystem::joinPath({"my","joined","path","myfile.txt"});
// Path = "my/joined/path/myfile.txt"
Path = openfluid::tools::Filesystem::joinPath({"/another","joined","path/anotherfile.txt"});
// Path = "/another/joined/path/anotherfile.txt"
static std::string joinPath(const std::vector< std::string > &PathParts)
FilesystemPath Path
Definition: FilesystemPath.hpp:308

◆ makeUniqueFile()

static std::string openfluid::tools::Filesystem::makeUniqueFile ( const std::string &  Path,
const std::string &  FileName 
)
static

Creates a unique file in the given path, using the given File name and extension as prefix and suffix. If the file already exists, it adds an incremental part to the file name. If the Path does not exists, it creates all needed parent directories.

Parameters
[in]Paththe given path for the file
[in]FileNamethe file name used to make a unique one
Returns
the full path of the created unique file

◆ makeUniqueSubdirectory()

static std::string openfluid::tools::Filesystem::makeUniqueSubdirectory ( const std::string &  Path,
const std::string &  SubdirName 
)
static

Creates a unique subdirectory in the given path, using the given subdirectory name as a prefix. If the subdirectory already exists, it adds an incremental suffix to the subdirectory name. It creates all parent directories necessary to create the subdirectory.

Parameters
[in]Paththe given path
[in]SubdirNamethe given path
Returns
the full path of the created unique subdirectory

◆ minimalBasename()

static std::string openfluid::tools::Filesystem::minimalBasename ( const std::string &  Path)
static

◆ pathSeparator()

constexpr static char openfluid::tools::Filesystem::pathSeparator ( )
inlinestaticconstexprnoexcept

◆ pathsListSeparator()

constexpr static char openfluid::tools::Filesystem::pathsListSeparator ( )
inlinestaticconstexprnoexcept

◆ readFile()

static std::string openfluid::tools::Filesystem::readFile ( const openfluid::tools::FilesystemPath FileObj)
static

Reads the content of a file

Parameters
[in]FileObjthe given path for the file
Returns
the content of the file

◆ renameFile()

static bool openfluid::tools::Filesystem::renameFile ( const std::string &  OriginalPath,
const std::string &  NewPath 
)
static

Rename a file.

Parameters
[in]OriginalPaththe original file path
[in]NewPaththe new file path
Returns
true if the file was successfully renamed, false otherwise

◆ tempPath()

static std::string openfluid::tools::Filesystem::tempPath ( )
static

Returns the system path for temporary files (e.g. '/tmp' on Linux, ...)

Returns
the path for temporary files

◆ writeFile()

static void openfluid::tools::Filesystem::writeFile ( const std::string &  Content,
const openfluid::tools::FilesystemPath FileObj 
)
static

Writes content into a file

Parameters
[in]Contentthe content to write
[in]FileObjthe given path for the file

The documentation for this class was generated from the following file: