Main MRPT website > C++ reference for MRPT 1.9.9
CDirectoryExplorer.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/system/os.h>
12 #include <deque>
13 
14 namespace mrpt
15 {
16 namespace system
17 {
18 #define FILE_ATTRIB_ARCHIVE 0x0020
19 #define FILE_ATTRIB_DIRECTORY 0x0010
20 
21 /** This class allows the enumeration of the files/directories that exist into a
22  * given path.
23  * The only existing method is "explore" and returns the list of found files &
24  * directories.
25  * Refer to the example in /samples/UTILS/directoryExplorer
26  *
27  * \sa CFileSystemWatcher
28  * \ingroup mrpt_system_grp
29  */
31 {
32  public:
33  /** This represents the information about each file.
34  * \sa
35  */
36  struct TFileInfo
37  {
38  /** The file name (without the whole path).
39  */
41 
42  /** The whole file path.
43  */
45 
46  /** Access and modification times.
47  */
49 
51 
52  /** The size of the file in bytes.
53  */
55  };
56 
57  /** The list type used in "explore".
58  * \sa explore
59  */
60  using TFileInfoList = std::deque<TFileInfo>;
61 
62  public:
63  /** The path of the directory to examine must be passed to this constructor,
64  * among the
65  * According to the following parameters, the object will collect the list
66  * of files, which
67  * can be modified later through other methods in this class.
68  * \param path The path to examine (IT MUST BE A DIRECTORY), e.g
69  * "d:\temp\", or "/usr/include/"
70  * \param mask One or the OR'ed combination of the values
71  * "FILE_ATTRIB_ARCHIVE" and "FILE_ATTRIB_DIRECTORY", depending on what file
72  * types do you want in the list (These values are platform-independent).
73  * \param outList The list of found files/directories is stored here.
74  * \sa sortByName
75  */
76  static void explore(
77  const std::string& path, const unsigned long mask,
78  TFileInfoList& outList);
79 
80  /** Sort the file entries by name, in ascending or descending order
81  */
82  static void sortByName(TFileInfoList& lstFiles, bool ascendingOrder = true);
83 
84  /** Remove from the list of files those whose extension does not coincide
85  * (without case) with the given one.
86  * Example: filterByExtension(lst,"txt");
87  */
88  static void filterByExtension(
89  TFileInfoList& lstFiles, const std::string& extension);
90 
91 }; // End of class def.
92 
93 } // End of namespace
94 } // End of namespace
static void filterByExtension(TFileInfoList &lstFiles, const std::string &extension)
Remove from the list of files those whose extension does not coincide (without case) with the given o...
static void explore(const std::string &path, const unsigned long mask, TFileInfoList &outList)
The path of the directory to examine must be passed to this constructor, among the According to the f...
GLenum GLint GLuint mask
Definition: glext.h:4050
std::string wholePath
The whole file path.
std::deque< TFileInfo > TFileInfoList
The list type used in "explore".
This class allows the enumeration of the files/directories that exist into a given path...
This represents the information about each file.
time_t accessTime
Access and modification times.
uint64_t fileSize
The size of the file in bytes.
GLsizei const GLchar ** string
Definition: glext.h:4101
static void sortByName(TFileInfoList &lstFiles, bool ascendingOrder=true)
Sort the file entries by name, in ascending or descending order.
std::string name
The file name (without the whole path).
unsigned __int64 uint64_t
Definition: rptypes.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019