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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: cb8dd5fc8 Sat Dec 7 21:55:39 2019 +0100 at sáb dic 7 22:00:13 CET 2019