Main MRPT website > C++ reference
MRPT logo
filesystem.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
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                 /** @defgroup filesystem Directories, files, and file names
00038                   * \ingroup mrpt_base_grp
00039                   * @{ */
00040 
00041                 /** Returns the name of a proposed temporary file name */
00042                 std::string BASE_IMPEXP getTempFileName();
00043 
00044                 /** Returns the current working directory.
00045                   */
00046                 std::string BASE_IMPEXP getcwd();
00047 
00048                 /** Creates a directory
00049                   * \return Returns false on any error, true on everything OK.
00050                   * \todo Seems to return false on Linux even after creating the directory OK.
00051                   */
00052                 bool  BASE_IMPEXP createDirectory( const std::string &dirName );
00053 
00054                 /** Deletes a single file. For multiple files see deleteFiles
00055                   * \return Returns false on any error, true on everything OK.
00056                   * \sa deleteFiles
00057                   */
00058                 bool BASE_IMPEXP deleteFile( const std::string &fileName );
00059 
00060                 /** 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.
00061                   * \sa deleteFile
00062                   */
00063                 void BASE_IMPEXP deleteFiles(const std::string &s);
00064 
00065                 /** Renames a file - If the target path is different and the filesystem allows it, it will be moved to the new location.
00066                   * \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.
00067                   */
00068                 bool BASE_IMPEXP renameFile( const std::string &oldFileName, const std::string &newFileName,  std::string *error_msg=NULL );
00069 
00070                 /** Delete all the files in a given directory (nothing done if directory does not exists, or path is a file).
00071                   * \sa deleteFile
00072                   * \return true on success
00073                   */
00074                 bool BASE_IMPEXP deleteFilesInDirectory(const std::string &s, bool deleteDirectoryAsWell = false );
00075 
00076                 /** Extract just the name (without extension) of a filename from a complete path plus name plus extension.
00077                   *  This function works for either "/" or "\" directory separators.
00078                   * \sa extractFileExtension,extractFileDirectory
00079                   */
00080                 std::string  BASE_IMPEXP extractFileName(const std::string& filePath);
00081 
00082                 /** Extract the extension of a filename.
00083                   *  For example, for "dummy.cpp", it will return "cpp".
00084                   *  If "ignore_gz" is true, the second extension will be returned if the file name
00085                   *   ends in ".gz", for example, for "foo.map.gz", this will return "map".
00086                   * \sa extractFileName,extractFileDirectory
00087                   */
00088                 std::string  BASE_IMPEXP extractFileExtension(const std::string &filePath, bool ignore_gz = false );
00089 
00090                 /** Extract the whole path (the directory) of a filename from a complete path plus name plus extension.
00091                   *  This function works for either "/" or "\" directory separators.
00092                   * \sa extractFileName,extractFileExtension
00093                   */
00094                 std::string  BASE_IMPEXP extractFileDirectory(const std::string &filePath);
00095 
00096                 /** Test if a given file (or directory) exists.
00097                   * \sa directoryExists
00098                   */
00099                 bool BASE_IMPEXP fileExists(const std::string& fileName);
00100 
00101                 /** Test if a given directory exists (it fails if the given path refers to an existing file).
00102                   * \sa fileExists
00103                   */
00104                 bool BASE_IMPEXP directoryExists(const std::string& fileName);
00105 
00106                 /** Replace invalid filename chars by underscores ('_').
00107                   *  Invalid chars are identified by those not being alphanumeric or: ".-#%$&()+[]{}"
00108                   */
00109                 std::string BASE_IMPEXP fileNameStripInvalidChars( const std::string &filename);
00110 
00111                 /** Replace the filename extension by another one.
00112                   *  Example:
00113                   *   \code
00114                   *     fileNameChangeExtension("cool.txt","bar") // -> "cool.bar"
00115                   *   \endcode
00116                   */
00117                 std::string BASE_IMPEXP fileNameChangeExtension( const std::string &filename, const std::string &newExtension );
00118 
00119                 /** Return the size of the given file, or size_t(-1) if some error is found accessing that file.
00120                   */
00121                 uint64_t BASE_IMPEXP getFileSize(const std::string &fileName);
00122 
00123                 /** @} */
00124 
00125 
00126         } // End of namespace
00127 
00128 } // End of namespace
00129 
00130 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011