MRPT
1.9.9
|
Header: #include <mrpt/system/filesystem.h>
.
Library: [mrpt-system]
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... | |
#define ASSERT_DIRECTORY_EXISTS_ | ( | DIR | ) |
Definition at line 27 of file filesystem.h.
Referenced by mrpt::apps::MonteCarloLocalization_Base::do_pf_localization().
#define ASSERT_FILE_EXISTS_ | ( | FIL | ) |
Definition at line 22 of file filesystem.h.
Referenced by generic_pf_test(), mrpt::apps::ICP_SLAM_App_Rawlog::impl_initialize(), mrpt::apps::RBPF_SLAM_App_Rawlog::impl_initialize(), mrpt::apps::MonteCarloLocalization_Rawlog::impl_initialize(), mrpt::apps::KFSLAMApp::initialize(), mrpt::apps::RawlogGrabberApp::initialize(), mrpt::apps::MonteCarloLocalization_Base::initialize(), mrpt::apps::ICP_SLAM_App_Base::initialize(), mrpt::apps::RBPF_SLAM_App_Base::initialize(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::TRGBDInfoFileParams::parseFile(), mrpt::apps::KFSLAMApp::Run_KF_SLAM(), TEST(), and GraphTester< my_graph_t >::test_optimize_compare_known_solution().
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.
Definition at line 390 of file filesystem.cpp.
References mrpt::system::directoryExists(), mrpt::system::os::fclose(), mrpt::system::fileExists(), mrpt::system::filePathSeparatorsToNative(), and mrpt::system::os::fopen().
bool mrpt::system::createDirectory | ( | const std::string & | dirName | ) |
Creates a directory.
Definition at line 161 of file filesystem.cpp.
References mrpt::format().
Referenced by mrpt::slam::CGridMapAligner::AlignPDF_robustMatch(), mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel(), mrpt::nav::CParameterizedTrajectoryGenerator::debugDumpInFiles(), mrpt::apps::MonteCarloLocalization_Base::do_pf_localization(), mrpt::nav::CAbstractPTGBasedReactive::enableLogFile(), mrpt::hmtslam::CHMTSLAM::initializeEmptyMap(), CGraphSlamHandler< GRAPH_T >::initOutputDir(), mrpt::apps::CGridMapAlignerApp::run(), mrpt::apps::RBPF_SLAM_App_Base::run(), mrpt::apps::ICP_SLAM_App_Base::run(), mrpt::apps::KFSLAMApp::Run_KF_SLAM(), mrpt::hwdrivers::CSwissRanger3DCamera::setPathForExternalImages(), mrpt::hwdrivers::CCameraSensor::setPathForExternalImages(), and mrpt::nav::PlannerRRT_SE2_TPS::solve().
bool mrpt::system::deleteFile | ( | const std::string & | fileName | ) |
Deletes a single file.
For multiple files see deleteFiles
Definition at line 182 of file filesystem.cpp.
Referenced by mrpt::system::deleteFilesInDirectory().
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.
Definition at line 190 of file filesystem.cpp.
References mrpt::system::os::fprintf(), MRPT_END, MRPT_START, mrpt::system::os::sprintf(), and mrpt::system::os::strcat().
Referenced by mrpt::apps::CGridMapAlignerApp::run().
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).
Definition at line 218 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::apps::MonteCarloLocalization_Base::do_pf_localization(), mrpt::hmtslam::CHMTSLAM::initializeEmptyMap(), CGraphSlamHandler< GRAPH_T >::initOutputDir(), mrpt::apps::ICP_SLAM_App_Base::run(), mrpt::apps::RBPF_SLAM_App_Base::run(), and mrpt::apps::KFSLAMApp::Run_KF_SLAM().
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).
Definition at line 137 of file filesystem.cpp.
References _stat.
Referenced by mrpt::system::copyFile(), mrpt::system::deleteFilesInDirectory(), mrpt::nav::CAbstractPTGBasedReactive::enableLogFile(), mrpt::system::find_mrpt_shared_dir(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::generateReportFiles(), mrpt::system::getShareMRPTDir(), CGraphSlamHandler< GRAPH_T >::initOutputDir(), mrpt::gui::CPanelCameraSelection::OnbtnBrowseRawlogClick(), and mrpt::system::CFileSystemWatcher::thread_win32_watch().
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.
This function works for either "/" or "\" directory separators.
Definition at line 78 of file filesystem.cpp.
Referenced by mrpt::obs::CRawlog::detectImagesDirectory(), mrpt::system::find_mrpt_shared_dir(), mrpt::system::getShareMRPTDir(), mrpt::apps::RBPF_SLAM_App_Rawlog::impl_initialize(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::initClass(), mrpt::gui::CPanelCameraSelection::OnbtnBrowseRawlogClick(), run_rnav_test(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::TRGBDInfoFileParams::setRawlogFile(), and TEST().
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".
Definition at line 98 of file filesystem.cpp.
Referenced by mrpt::apps::MonteCarloLocalization_Base::do_pf_localization(), mrpt::system::CDirectoryExplorer::filterByExtension(), mrpt::obs::CObservation3DRangeScan::load(), mrpt::maps::CPointsMapXYZI::loadFromKittiVelodyneFile(), mrpt::ros1bridge::MapHdl::loadMap(), mrpt::obs::CObservation3DRangeScan::rangeImage_getExternalStorageFile(), mrpt::apps::CGridMapAlignerApp::run(), run_test_pf_localization(), and TEST().
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.
This function works for either "/" or "\" directory separators.
Definition at line 62 of file filesystem.cpp.
Referenced by mrpt::obs::CRawlog::detectImagesDirectory(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::initClass(), mrpt::hwdrivers::TCaptureOptions_DUO3D::m_camera_ext_params_from_yml(), mrpt::hwdrivers::TCaptureOptions_DUO3D::m_camera_int_params_from_yml(), mrpt::hwdrivers::TCaptureOptions_DUO3D::m_rectify_map_from_yml(), mrpt::system::CTimeLogger::saveToMFile(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::TRGBDInfoFileParams::setRawlogFile(), and TEST().
bool mrpt::system::fileExists | ( | const std::string & | fileName | ) |
Test if a given file (or directory) exists.
Definition at line 128 of file filesystem.cpp.
References _access.
Referenced by mrpt::maps::CGasConcentrationGridMap2D::build_Gaussian_Wind_Grid(), mrpt::system::copyFile(), mrpt::obs::CRawlog::detectImagesDirectory(), mrpt::apps::MonteCarloLocalization_Base::do_pf_localization(), mrpt::nav::CAbstractPTGBasedReactive::enableLogFile(), generic_icp_slam_test(), generic_kf_slam_test(), generic_rbpf_slam_test(), mrpt::slam::CMetricMapBuilder::loadCurrentMapFromFile(), mrpt::ros1bridge::MapHdl::loadMap(), mrpt::hmtslam::CHMTSLAM::loadOptions(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::loadParams(), CGraphSlamHandler< GRAPH_T >::readConfigFname(), readFileWithPoses(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFile(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFileRGBD_TUM(), mrpt::apps::CGridMapAlignerApp::run(), mrpt::apps::KFSLAMApp::Run_KF_SLAM(), run_rnav_test(), run_test_pf_localization(), TEST(), and mrpt::obs::CObservationPointCloud::unload().
std::string mrpt::system::fileNameChangeExtension | ( | const std::string & | filePath, |
const std::string & | newExtension | ||
) |
Replace the filename extension by another one.
Example:
Definition at line 373 of file filesystem.cpp.
Referenced by mrpt::obs::CObservation3DRangeScan::points3D_convertToExternalStorage(), mrpt::obs::CObservation3DRangeScan::rangeImage_convertToExternalStorage(), mrpt::obs::CObservation3DRangeScan::rangeImage_getExternalStorageFile(), and TEST().
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.
Invalid chars are: '<','>',':','"','/','\','|','?','*'
Definition at line 329 of file filesystem.cpp.
Referenced by mrpt::hwdrivers::CGPSInterface::doProcess(), mrpt::hwdrivers::CCameraSensor::getNextFrame(), mrpt::hwdrivers::CSwissRanger3DCamera::getNextObservation(), mrpt::hwdrivers::CNTRIPEmitter::initialize(), mrpt::nav::CParameterizedTrajectoryGenerator::initialize(), CGraphSlamHandler< GRAPH_T >::initOutputDir(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::initResultsFile(), mrpt::hwdrivers::CVelodyneScanner::receivePackets(), mrpt::apps::RawlogGrabberApp::run(), mrpt::maps::CMultiMetricMap::saveMetricMapRepresentationToFile(), mrpt::system::CTimeLogger::saveToMFile(), CGraphSlamHandler< GRAPH_T >::setResultsDirName(), mrpt::hwdrivers::CCameraSensor::thread_save_images(), and mrpt::system::CTimeLoggerSaveAtDtor::~CTimeLoggerSaveAtDtor().
std::string mrpt::system::filePathSeparatorsToNative | ( | const std::string & | filePath | ) |
Windows: replace all '/'->'\' , in Linux/MacOS: replace all '\'->'/'.
Definition at line 612 of file filesystem.cpp.
Referenced by mrpt::system::copyFile(), and TEST().
std::string mrpt::system::getcwd | ( | ) |
Returns the current working directory.
Definition at line 251 of file filesystem.cpp.
References MRPT_END, MRPT_START, mrpt::math::size(), and THROW_EXCEPTION.
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 628 of file filesystem.cpp.
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 351 of file filesystem.cpp.
Referenced by mrpt::io::CFileGZInputStream::open().
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 641 of file filesystem.cpp.
References mrpt::system::directoryExists(), and mrpt::system::extractFileDirectory().
Referenced by TEST().
std::string mrpt::system::getTempFileName | ( | ) |
Returns the name of a proposed temporary file name.
Definition at line 283 of file filesystem.cpp.
References ASSERT_.
Referenced by mrpt::io::zip::decompress_gz_data_block(), generic_icp_slam_test(), generic_kf_slam_test(), generic_pf_test(), generic_rbpf_slam_test(), run_rnav_test(), and TEST().
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.
Definition at line 309 of file filesystem.cpp.
Referenced by CGraphSlamHandler< GRAPH_T >::initOutputDir().
Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020 |