Main MRPT website > C++ reference for MRPT 1.9.9
Macros | Functions
Directories, files, and file names (in #include

Detailed Description

<mrpt/system/filesystem.h>)

Macros

#define ASSERT_FILE_EXISTS_(FIL)
 
#define ASSERT_DIRECTORY_EXISTS_(DIR)
 

Functions

std::string mrpt::system::getTempFileName ()
 Returns the name of a proposed temporary file name. More...
 
std::string mrpt::system::getcwd ()
 Returns the current working directory
More...
 
std::string mrpt::system::getShareMRPTDir ()
 Attempts to find the directory [PREFIX/]share/mrpt/ and returns its absolute path, or empty string if not found. More...
 
bool mrpt::system::createDirectory (const std::string &dirName)
 Creates a directory. More...
 
bool mrpt::system::deleteFile (const std::string &fileName)
 Deletes a single file. More...
 
void 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 mrpt::system::renameFile (const std::string &oldFileName, const std::string &newFileName, std::string *error_msg=nullptr)
 Renames a file - If the target path is different and the filesystem allows it, it will be moved to the new location. More...
 
bool 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 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 mrpt::system::extractFileExtension (const std::string &filePath, bool ignore_gz=false)
 Extract the extension of a filename. More...
 
std::string 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 mrpt::system::fileExists (const std::string &fileName)
 Test if a given file (or directory) exists. More...
 
bool 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 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 mrpt::system::fileNameChangeExtension (const std::string &filename, const std::string &newExtension)
 Replace the filename extension by another one. More...
 
uint64_t 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 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 mrpt::system::filePathSeparatorsToNative (const std::string &filePath)
 Windows: replace all '/'->'\' , in Linux/MacOS: replace all '\'->'/'. More...
 
bool mrpt::system::copyFile (const std::string &sourceFile, const std::string &targetFile, std::string *outErrStr=nullptr, bool copyAttribs=true)
 Copies file sourceFile to targetFile. More...
 

Macro Definition Documentation

◆ ASSERT_DIRECTORY_EXISTS_

#define ASSERT_DIRECTORY_EXISTS_ (   DIR)
Value:
std::string("Assert directory existence failed: ") + \
::std::string(DIR))

Definition at line 27 of file filesystem.h.

◆ ASSERT_FILE_EXISTS_

#define ASSERT_FILE_EXISTS_ (   FIL)
Value:
std::string("Assert file existence failed: ") + ::std::string(FIL))

Definition at line 22 of file filesystem.h.

Function Documentation

◆ copyFile()

bool mrpt::system::copyFile ( const std::string sourceFile,
const std::string targetFile,
std::string outErrStr = nullptr,
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

Definition at line 387 of file filesystem.cpp.

References mrpt::system::directoryExists(), mrpt::system::os::fclose(), mrpt::system::fileExists(), mrpt::system::filePathSeparatorsToNative(), and mrpt::system::os::fopen().

◆ createDirectory()

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

◆ deleteFile()

bool 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

Definition at line 179 of file filesystem.cpp.

Referenced by mrpt::system::deleteFilesInDirectory().

◆ deleteFiles()

void 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

Definition at line 187 of file filesystem.cpp.

References mrpt::system::os::fprintf(), MRPT_END, MRPT_START, mrpt::system::os::sprintf(), and mrpt::system::os::strcat().

◆ deleteFilesInDirectory()

bool 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

Definition at line 215 of file filesystem.cpp.

References _rmdir, mrpt::system::deleteFile(), mrpt::system::directoryExists(), mrpt::system::CDirectoryExplorer::explore(), FILE_ATTRIB_ARCHIVE, and FILE_ATTRIB_DIRECTORY.

Referenced by mrpt::slam::CGridMapAligner::AlignPDF_robustMatch(), mrpt::hmtslam::CHMTSLAM::initializeEmptyMap(), and CGraphSlamHandler< GRAPH_T >::initOutputDir().

◆ directoryExists()

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

◆ extractFileDirectory()

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

◆ extractFileExtension()

string 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

Definition at line 97 of file filesystem.cpp.

Referenced by mrpt::vision::checkerBoardCameraCalibration(), mrpt::system::CDirectoryExplorer::filterByExtension(), mrpt::obs::CObservation3DRangeScan::load(), run_test_pf_localization(), and TEST().

◆ extractFileName()

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

◆ fileExists()

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

◆ fileNameChangeExtension()

std::string mrpt::system::fileNameChangeExtension ( const std::string filePath,
const std::string newExtension 
)

Replace the filename extension by another one.

Example:

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


Definition at line 370 of file filesystem.cpp.

Referenced by mrpt::obs::CObservation3DRangeScan::points3D_convertToExternalStorage(), mrpt::obs::CObservation3DRangeScan::rangeImage_convertToExternalStorage(), and TEST().

◆ fileNameStripInvalidChars()

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

◆ filePathSeparatorsToNative()

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

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

Definition at line 609 of file filesystem.cpp.

Referenced by mrpt::system::copyFile(), and TEST().

◆ getcwd()

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

Returns the current working directory

Definition at line 248 of file filesystem.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION.

◆ getFileModificationTime()

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

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


Definition at line 625 of file filesystem.cpp.

◆ getFileSize()

uint64_t 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.


Definition at line 350 of file filesystem.cpp.

Referenced by mrpt::io::CFileGZInputStream::open().

◆ getShareMRPTDir()

std::string 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.

Definition at line 636 of file filesystem.cpp.

References mrpt::system::directoryExists(), and mrpt::system::extractFileDirectory().

◆ getTempFileName()

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

Returns the name of a proposed temporary file name.

Definition at line 282 of file filesystem.cpp.

References ASSERT_.

Referenced by mrpt::io::zip::decompress_gz_data_block(), run_rnav_test(), and TEST().

◆ renameFile()

bool mrpt::system::renameFile ( const std::string oldFileName,
const std::string newFileName,
std::string error_msg = nullptr 
)

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.

Definition at line 308 of file filesystem.cpp.

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

mrpt::system::directoryExists
bool directoryExists(const std::string &fileName)
Test if a given directory exists (it fails if the given path refers to an existing file).
Definition: filesystem.cpp:136
mrpt::system::fileExists
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:127
mrpt::system::fileNameChangeExtension
std::string fileNameChangeExtension(const std::string &filename, const std::string &newExtension)
Replace the filename extension by another one.
Definition: filesystem.cpp:370
ASSERTMSG_
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
string
GLsizei const GLchar ** string
Definition: glext.h:4101



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST