00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2011 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef MRPT_FILESYSTEM_H 00029 #define MRPT_FILESYSTEM_H 00030 00031 #include <mrpt/utils/utils_defs.h> 00032 00033 namespace mrpt 00034 { 00035 namespace system 00036 { 00037 /** @name Directories, files, and file names 00038 @{*/ 00039 00040 /** Returns the name of a proposed temporary file name */ 00041 std::string BASE_IMPEXP getTempFileName(); 00042 00043 /** Returns the current working directory. 00044 */ 00045 std::string BASE_IMPEXP getcwd(); 00046 00047 /** Creates a directory 00048 * \return Returns false on any error, true on everything OK. 00049 * \todo Seems to return false on Linux even after creating the directory OK. 00050 */ 00051 bool BASE_IMPEXP createDirectory( const std::string &dirName ); 00052 00053 /** Deletes a single file. For multiple files see deleteFiles 00054 * \return Returns false on any error, true on everything OK. 00055 * \sa deleteFiles 00056 */ 00057 bool BASE_IMPEXP deleteFile( const std::string &fileName ); 00058 00059 /** 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. 00060 * \sa deleteFile 00061 */ 00062 void BASE_IMPEXP deleteFiles(const std::string &s); 00063 00064 /** Renames a file - If the target path is different and the filesystem allows it, it will be moved to the new location. 00065 * \return 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. 00066 */ 00067 bool BASE_IMPEXP renameFile( const std::string &oldFileName, const std::string &newFileName, std::string *error_msg=NULL ); 00068 00069 /** Delete all the files in a given directory (nothing done if directory does not exists, or path is a file). 00070 * \sa deleteFile 00071 * \return true on success 00072 */ 00073 bool BASE_IMPEXP deleteFilesInDirectory(const std::string &s, bool deleteDirectoryAsWell = false ); 00074 00075 /** Extract just the name (without extension) of a filename from a complete path plus name plus extension. 00076 * This function works for either "/" or "\" directory separators. 00077 * \sa extractFileExtension,extractFileDirectory 00078 */ 00079 std::string BASE_IMPEXP extractFileName(const std::string& filePath); 00080 00081 /** Extract the extension of a filename. 00082 * For example, for "dummy.cpp", it will return "cpp". 00083 * If "ignore_gz" is true, the second extension will be returned if the file name 00084 * ends in ".gz", for example, for "foo.map.gz", this will return "map". 00085 * \sa extractFileName,extractFileDirectory 00086 */ 00087 std::string BASE_IMPEXP extractFileExtension(const std::string &filePath, bool ignore_gz = false ); 00088 00089 /** Extract the whole path (the directory) of a filename from a complete path plus name plus extension. 00090 * This function works for either "/" or "\" directory separators. 00091 * \sa extractFileName,extractFileExtension 00092 */ 00093 std::string BASE_IMPEXP extractFileDirectory(const std::string &filePath); 00094 00095 /** Test if a given file (or directory) exists. 00096 * \sa directoryExists 00097 */ 00098 bool BASE_IMPEXP fileExists(const std::string& fileName); 00099 00100 /** Test if a given directory exists (it fails if the given path refers to an existing file). 00101 * \sa fileExists 00102 */ 00103 bool BASE_IMPEXP directoryExists(const std::string& fileName); 00104 00105 /** Replace invalid filename chars by underscores ('_'). 00106 * Invalid chars are identified by those not being alphanumeric or: ".-#%$&()+[]{}" 00107 */ 00108 std::string BASE_IMPEXP fileNameStripInvalidChars( const std::string &filename); 00109 00110 /** Replace the filename extension by another one. 00111 * Example: 00112 * \code 00113 * fileNameChangeExtension("cool.txt","bar") // -> "cool.bar" 00114 * \endcode 00115 */ 00116 std::string BASE_IMPEXP fileNameChangeExtension( const std::string &filename, const std::string &newExtension ); 00117 00118 /** Return the size of the given file, or size_t(-1) if some error is found accessing that file. 00119 */ 00120 uint64_t BASE_IMPEXP getFileSize(const std::string &fileName); 00121 00122 /** @} */ 00123 00124 00125 } // End of namespace 00126 00127 } // End of namespace 00128 00129 #endif
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011 |