MRPT  2.0.4
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, 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 
10 #include <mrpt/core/exceptions.h>
12 #include <mrpt/system/filesystem.h>
13 #include <iostream>
14 #include <string>
15 
16 using namespace mrpt;
17 using namespace mrpt::system;
18 using namespace std;
19 
20 // ------------------------------------------------------
21 // TestDirExplorer
22 // ------------------------------------------------------
23 void TestDirExplorer()
24 {
26 
27  string path(mrpt::system::getcwd());
28  printf("Exploring path: %s\n", path.c_str());
29 
32 
33  printf("Found %i files:\n", (unsigned int)lst.size());
34 
35  for (CDirectoryExplorer::TFileInfoList::iterator it = lst.begin();
36  it != lst.end(); ++it)
37  {
38  printf("name: %s\n", it->name.c_str());
39  printf("wholePath: %s\n", it->wholePath.c_str());
40  printf("isDir: %c\n", it->isDir ? 'Y' : 'N');
41  printf("size: %lu bytes\n", (unsigned long)it->fileSize);
42  printf("-----------------------\n");
43  }
44 }
45 
46 // ------------------------------------------------------
47 // TestFileNames
48 // ------------------------------------------------------
49 void TestFileNames()
50 {
51  // Test extractFileName
52  string S;
53 
54  S = "foo.bar";
55  cout << "file: " << S
56  << " -> extractFileName : " << mrpt::system::extractFileName(S)
57  << endl;
58 
59  S = "foo.b";
60  cout << "file: " << S
61  << " -> extractFileName : " << mrpt::system::extractFileName(S)
62  << endl;
63 
64  S = "foo.bardotbar.too";
65  cout << "file: " << S
66  << " -> extractFileName : " << mrpt::system::extractFileName(S)
67  << endl;
68 
69  S = "foo";
70  cout << "file: " << S
71  << " -> extractFileName : " << mrpt::system::extractFileName(S)
72  << endl;
73 
74  S = "foo.";
75  cout << "file: " << S
76  << " -> extractFileName : " << mrpt::system::extractFileName(S)
77  << endl;
78 }
79 
80 // ------------------------------------------------------
81 // MAIN
82 // ------------------------------------------------------
83 int main()
84 {
85  try
86  {
88  TestFileNames();
89 
90  return 0;
91  }
92  catch (const std::exception& e)
93  {
94  std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
95  return -1;
96  }
97 }
filesystem.h
exceptions.h
TestDirExplorer
void TestDirExplorer()
Definition: vision_stereo_rectify/test.cpp:23
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
FILE_ATTRIB_ARCHIVE
#define FILE_ATTRIB_ARCHIVE
Definition: CDirectoryExplorer.h:16
FILE_ATTRIB_DIRECTORY
#define FILE_ATTRIB_DIRECTORY
Definition: CDirectoryExplorer.h:17
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::system::CDirectoryExplorer::TFileInfoList
std::deque< TFileInfo > TFileInfoList
The list type used in "explore".
Definition: CDirectoryExplorer.h:58
mrpt::system::getcwd
std::string getcwd()
Returns the current working directory
Definition: filesystem.cpp:251
TestFileNames
void TestFileNames()
Definition: vision_stereo_rectify/test.cpp:49
CDirectoryExplorer.h
mrpt::system::extractFileName
std::string extractFileName(const std::string &filePath)
Extract just the name (without extension) of a filename from a complete path plus name plus extension...
Definition: filesystem.cpp:62
mrpt::exception_to_str
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
mrpt::system::CDirectoryExplorer::explore
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...
Definition: CDirectoryExplorer.cpp:47
mrpt::system
Definition: backtrace.h:14



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 17:54:30 UTC 2020