Main MRPT website > C++ reference
MRPT logo
CDirectoryExplorer.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CDirectoryExplorer_H
29 #define CDirectoryExplorer_H
30 
31 #include <mrpt/utils/utils_defs.h>
32 #include <mrpt/system/os.h>
33 
34 /*---------------------------------------------------------------
35  Class
36  ---------------------------------------------------------------*/
37 namespace mrpt
38 {
39  namespace system
40  {
41  #define FILE_ATTRIB_ARCHIVE 0x0020
42  #define FILE_ATTRIB_DIRECTORY 0x0010
43 
44  /** This class allows the enumeration of the files/directories that exist into a given path.
45  * The only existing method is "explore" and returns the list of found files & directories.
46  * Refer to the example in /samples/UTILS/directoryExplorer
47  *
48  * \sa CFileSystemWatcher
49  * \ingroup mrpt_base_grp
50  */
52  {
53  public:
54  /** This represents the information about each file.
55  * \sa
56  */
58  {
59  /** The file name (without the whole path).
60  */
61  std::string name;
62 
63  /** The whole file path.
64  */
65  std::string wholePath;
66 
67  /** Access and modification times.
68  */
69  time_t accessTime,modTime;
70 
71  bool isDir, isSymLink;
72 
73  /** The size of the file in bytes.
74  */
75  uint64_t fileSize;
76  };
77 
78  /** The list type used in "explore".
79  * \sa explore
80  */
81  typedef std::deque<TFileInfo> TFileInfoList;
82 
83  public:
84  /** The path of the directory to examine must be passed to this constructor, among the
85  * According to the following parameters, the object will collect the list of files, which
86  * can be modified later through other methods in this class.
87  * \param path The path to examine (IT MUST BE A DIRECTORY), e.g "d:\temp\", or "/usr/include/"
88  * \param mask One or the OR'ed combination of the values "FILE_ATTRIB_ARCHIVE" and "FILE_ATTRIB_DIRECTORY", depending on what file types do you want in the list (These values are platform-independent).
89  * \param outList The list of found files/directories is stored here.
90  * \sa sortByName
91  */
92  static void explore(
93  const std::string &path,
94  const unsigned long mask,
95  TFileInfoList &outList );
96 
97  /** Sort the file entries by name, in ascending or descending order
98  */
99  static void sortByName( TFileInfoList &lstFiles, bool ascendingOrder=true );
100 
101  /** Remove from the list of files those whose extension does not coincide (without case) with the given one.
102  * Example: filterByExtension(lst,"txt");
103  */
104  static void filterByExtension( TFileInfoList &lstFiles, const std::string &extension );
105 
106  }; // End of class def.
107 
108  } // End of namespace
109 } // End of namespace
110 
111 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013