Main MRPT website > C++ reference for MRPT 1.5.3
Functions
Directories, files, and file names (in #include <mrpt/system/filesystem.h>)

Detailed Description

Collaboration diagram for Directories, files, and file names (in #include <mrpt/system/filesystem.h>):

Functions

std::string BASE_IMPEXP mrpt::system::getTempFileName ()
 Returns the name of a proposed temporary file name. More...
 
std::string BASE_IMPEXP mrpt::system::getcwd ()
 Returns the current working directory. More...
 
std::string BASE_IMPEXP mrpt::system::getShareMRPTDir ()
 Attempts to find the directory [PREFIX/]share/mrpt/ and returns its absolute path, or empty string if not found. More...
 
bool BASE_IMPEXP mrpt::system::createDirectory (const std::string &dirName)
 Creates a directory. More...
 
bool BASE_IMPEXP mrpt::system::deleteFile (const std::string &fileName)
 Deletes a single file. More...
 
void BASE_IMPEXP mrpt::system::deleteFiles (const std::string &s)
 Delete one or more files, especified by the (optional) path and the file name (including '?' or '*') - Use forward slash ('/') for directories for compatibility between Windows and Linux, since they will be internally traslated into backward slashes ('\') if MRPT is compiled under Windows. More...
 
bool BASE_IMPEXP mrpt::system::renameFile (const std::string &oldFileName, const std::string &newFileName, std::string *error_msg=NULL)
 Renames a file - If the target path is different and the filesystem allows it, it will be moved to the new location. More...
 
bool BASE_IMPEXP mrpt::system::deleteFilesInDirectory (const std::string &s, bool deleteDirectoryAsWell=false)
 Delete all the files in a given directory (nothing done if directory does not exists, or path is a file). More...
 
std::string BASE_IMPEXP mrpt::system::extractFileName (const std::string &filePath)
 Extract just the name (without extension) of a filename from a complete path plus name plus extension. More...
 
std::string BASE_IMPEXP mrpt::system::extractFileExtension (const std::string &filePath, bool ignore_gz=false)
 Extract the extension of a filename. More...
 
std::string BASE_IMPEXP mrpt::system::extractFileDirectory (const std::string &filePath)
 Extract the whole path (the directory) of a filename from a complete path plus name plus extension. More...
 
bool BASE_IMPEXP mrpt::system::fileExists (const std::string &fileName)
 Test if a given file (or directory) exists. More...
 
bool BASE_IMPEXP mrpt::system::directoryExists (const std::string &fileName)
 Test if a given directory exists (it fails if the given path refers to an existing file). More...
 
std::string BASE_IMPEXP mrpt::system::fileNameStripInvalidChars (const std::string &filename, const char replacement_to_invalid_chars='_')
 Replace invalid filename chars by underscores ('_') or any other user-given char. More...
 
std::string BASE_IMPEXP mrpt::system::fileNameChangeExtension (const std::string &filename, const std::string &newExtension)
 Replace the filename extension by another one. More...
 
uint64_t BASE_IMPEXP mrpt::system::getFileSize (const std::string &fileName)
 Return the size of the given file, or size_t(-1) if some error is found accessing that file. More...
 
time_t BASE_IMPEXP mrpt::system::getFileModificationTime (const std::string &filename)
 Return the time of the file last modification, or "0" if the file doesn't exist. More...
 
std::string BASE_IMPEXP mrpt::system::filePathSeparatorsToNative (const std::string &filePath)
 Windows: replace all '/'->'\' , in Linux/MacOS: replace all '\'->'/'. More...
 
bool BASE_IMPEXP mrpt::system::copyFile (const std::string &sourceFile, const std::string &targetFile, std::string *outErrStr=NULL, bool copyAttribs=true)
 Copies file sourceFile to targetFile. More...
 

Function Documentation

◆ copyFile()

bool BASE_IMPEXP mrpt::system::copyFile ( const std::string &  sourceFile,
const std::string &  targetFile,
std::string *  outErrStr = NULL,
bool  copyAttribs = true 
)

Copies file sourceFile to targetFile.

If the target file exists, it will be overwritten. If the target file cannot be overwritten, the function first tries to change its permissions/attributes and retries opening it for write.

Note
Only for Windows: After a successful copy, if copyAttribs is true, the attributes of the source file are also copied. Note that not all attributes can be copied: http://msdn2.microsoft.com/en-us/library/aa365535.aspx
Returns
true on success, false on any error, whose description can be optionally get in outErrStr

◆ createDirectory()

bool BASE_IMPEXP mrpt::system::createDirectory ( const std::string &  dirName)

Creates a directory.

Returns
Returns false on any error, true on directory created or already existed.

Referenced by CGraphSlamHandler< GRAPH_T >::initOutputDir().

◆ deleteFile()

bool BASE_IMPEXP mrpt::system::deleteFile ( const std::string &  fileName)

Deletes a single file.

For multiple files see deleteFiles

Returns
Returns false on any error, true on everything OK.
See also
deleteFiles

◆ deleteFiles()

void BASE_IMPEXP mrpt::system::deleteFiles ( const std::string &  s)

Delete one or more files, especified by the (optional) path and the file name (including '?' or '*') - Use forward slash ('/') for directories for compatibility between Windows and Linux, since they will be internally traslated into backward slashes ('\') if MRPT is compiled under Windows.

See also
deleteFile

◆ deleteFilesInDirectory()

bool BASE_IMPEXP mrpt::system::deleteFilesInDirectory ( const std::string &  s,
bool  deleteDirectoryAsWell = false 
)

Delete all the files in a given directory (nothing done if directory does not exists, or path is a file).

See also
deleteFile
Returns
true on success

Referenced by CGraphSlamHandler< GRAPH_T >::initOutputDir().

◆ directoryExists()

bool BASE_IMPEXP mrpt::system::directoryExists ( const std::string &  fileName)

Test if a given directory exists (it fails if the given path refers to an existing file).

See also
fileExists

Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::generateReportFiles(), and CGraphSlamHandler< GRAPH_T >::initOutputDir().

◆ extractFileDirectory()

std::string BASE_IMPEXP mrpt::system::extractFileDirectory ( const std::string &  filePath)

Extract the whole path (the directory) of a filename from a complete path plus name plus extension.

This function works for either "/" or "\" directory separators.

See also
extractFileName,extractFileExtension

Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::initClass(), and mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::TRGBDInfoFileParams::setRawlogFile().

◆ extractFileExtension()

std::string BASE_IMPEXP mrpt::system::extractFileExtension ( const std::string &  filePath,
bool  ignore_gz = false 
)

Extract the extension of a filename.

For example, for "dummy.cpp", it will return "cpp". If "ignore_gz" is true, the second extension will be returned if the file name ends in ".gz", for example, for "foo.map.gz", this will return "map".

See also
extractFileName,extractFileDirectory

◆ extractFileName()

std::string BASE_IMPEXP mrpt::system::extractFileName ( const std::string &  filePath)

Extract just the name (without extension) of a filename from a complete path plus name plus extension.

This function works for either "/" or "\" directory separators.

See also
extractFileExtension,extractFileDirectory

Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::initClass(), and mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::TRGBDInfoFileParams::setRawlogFile().

◆ fileExists()

bool BASE_IMPEXP mrpt::system::fileExists ( const std::string &  fileName)

◆ fileNameChangeExtension()

std::string BASE_IMPEXP mrpt::system::fileNameChangeExtension ( const std::string &  filename,
const std::string &  newExtension 
)

Replace the filename extension by another one.

Example:

fileNameChangeExtension("cool.txt","bar") // -> "cool.bar"

◆ fileNameStripInvalidChars()

std::string BASE_IMPEXP mrpt::system::fileNameStripInvalidChars ( const std::string &  filename,
const char  replacement_to_invalid_chars = '_' 
)

Replace invalid filename chars by underscores ('_') or any other user-given char.

Invalid chars are: '<','>',':','"','/','\','|','?','*'

Referenced by CGraphSlamHandler< GRAPH_T >::initOutputDir(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::initResultsFile(), and CGraphSlamHandler< GRAPH_T >::setResultsDirName().

◆ filePathSeparatorsToNative()

std::string BASE_IMPEXP mrpt::system::filePathSeparatorsToNative ( const std::string &  filePath)

Windows: replace all '/'->'\' , in Linux/MacOS: replace all '\'->'/'.

◆ getcwd()

std::string BASE_IMPEXP mrpt::system::getcwd ( )

Returns the current working directory.

◆ getFileModificationTime()

time_t BASE_IMPEXP mrpt::system::getFileModificationTime ( const std::string &  filename)

Return the time of the file last modification, or "0" if the file doesn't exist.

◆ getFileSize()

uint64_t BASE_IMPEXP mrpt::system::getFileSize ( const std::string &  fileName)

Return the size of the given file, or size_t(-1) if some error is found accessing that file.

◆ getShareMRPTDir()

std::string BASE_IMPEXP mrpt::system::getShareMRPTDir ( )

Attempts to find the directory [PREFIX/]share/mrpt/ and returns its absolute path, or empty string if not found.

Example return paths: Linux after installing = /usr/share/mrpt/; manually-built system = [CMAKE_SOURCE_DIR]/share/mrpt/, etc.

◆ getTempFileName()

std::string BASE_IMPEXP mrpt::system::getTempFileName ( )

Returns the name of a proposed temporary file name.

◆ renameFile()

bool BASE_IMPEXP mrpt::system::renameFile ( const std::string &  oldFileName,
const std::string &  newFileName,
std::string *  error_msg = NULL 
)

Renames a file - If the target path is different and the filesystem allows it, it will be moved to the new location.

Returns
false on any error. In that case, if a pointer to a receiver string is passed in error_msg, a description of the error is saved there.

Referenced by CGraphSlamHandler< GRAPH_T >::initOutputDir().




Page generated by Doxygen 1.8.13 for MRPT 1.5.3 at Tue Aug 22 01:03:35 UTC 2017