MRPT  2.0.4
filesystem.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 "system-precomp.h" // Precompiled headers
11 
12 #include <mrpt/core/exceptions.h> // for MRPT_END, MRPT_START, e
13 #include <mrpt/core/format.h>
15 #include <mrpt/system/filesystem.h>
16 #include <mrpt/system/os.h> // for sprintf
17 
18 #include <algorithm>
19 #include <cstdio>
20 #include <cstring>
21 #include <string>
22 #include <vector>
23 
24 #ifdef _WIN32
25 #include <windows.h>
26 
27 #include <conio.h>
28 #include <direct.h>
29 #include <io.h>
30 #include <process.h>
31 #include <sys/utime.h>
32 #include <tlhelp32.h>
33 #else
34 #include <sys/time.h>
35 #include <termios.h>
36 #include <unistd.h>
37 #include <utime.h>
38 #include <cerrno>
39 #include <ctime>
40 #endif
41 
42 #include <sys/stat.h>
43 #include <sys/types.h>
44 
45 #if !defined(_MSC_VER)
46 #define _access access
47 #define _rmdir rmdir
48 #ifndef _stat // It seems MinGW already defines this.
49 #define _stat stat
50 #endif
51 #endif
52 
53 using namespace mrpt;
54 using namespace mrpt::system;
55 using namespace std;
56 
57 /*---------------------------------------------------------------
58  ExtractFileName
59  Extracts just the name of a filename from a
60  complete path plus name plus extension.
61  ---------------------------------------------------------------*/
62 string mrpt::system::extractFileName(const string& filePath)
63 {
64  int i, dotPos = int(filePath.size());
65  if (filePath.size() < 2) return string("");
66 
67  for (i = (int)filePath.size() - 1;
68  i >= 0 && !(filePath[i] == '\\' || filePath[i] == '/'); i--)
69  if (dotPos == int(filePath.size()) && filePath[i] == '.') dotPos = i;
70  return filePath.substr(i + 1, dotPos - i - 1);
71 }
72 
73 /*---------------------------------------------------------------
74  ExtractFileDirectory
75  Extracts just the directory of a filename from a
76  complete path plus name plus extension.
77  ---------------------------------------------------------------*/
78 string mrpt::system::extractFileDirectory(const string& filePath)
79 {
80  if (filePath.size() < 2) return filePath;
81 
82  // Search the first "/" or "\" from the right:
83  int i;
84  for (i = (int)filePath.size() - 1; i > 0; i--)
85  if (filePath[i] == '\\' || filePath[i] == '/') break;
86 
87  if (!i)
88  return string("");
89  else
90  return filePath.substr(0, i + 1);
91 }
92 
93 /*---------------------------------------------------------------
94  ExtractFileName
95  Extracts just the name of a filename from a
96  complete path plus name plus extension.
97  ---------------------------------------------------------------*/
99  const string& filePath, bool ignore_gz)
100 {
101  if (filePath.size() < 2) return string("");
102 
103  size_t i_end = filePath.size() - 1;
104 
105  int i = (int)(i_end);
106  while (i > 0)
107  {
108  if (filePath[i] == '.')
109  {
110  string the_ext = filePath.substr(i + 1, i_end - i);
111  if (!ignore_gz || the_ext != "gz")
112  return the_ext;
113  else
114  {
115  i_end = --i;
116  }
117  }
118  else
119  i--;
120  }
121  // No extension:
122  return string("");
123 }
124 
125 /*---------------------------------------------------------------
126  FileExists
127  ---------------------------------------------------------------*/
128 bool mrpt::system::fileExists(const string& path)
129 {
130  return 0 ==
131  _access(path.c_str(), 0x00); // 0x00 = Check for existence only!
132 }
133 
134 /*---------------------------------------------------------------
135  directoryExists
136  ---------------------------------------------------------------*/
137 bool mrpt::system::directoryExists(const std::string& _path)
138 {
139  std::string path = _path;
140 
141  // Remove the trailing "/" or "\\":
142  if (!path.empty() && (*path.rbegin() == '/' || *path.rbegin() == '\\'))
143  path = path.substr(0, path.size() - 1);
144 
145  // Verify it's a directory:
146  struct _stat buf
147  {
148  };
149  if (0 != _stat(path.c_str(), &buf)) return false;
150 
151 #ifdef _WIN32
152  return 0 != (buf.st_mode & _S_IFDIR);
153 #else
154  return S_ISDIR(buf.st_mode);
155 #endif
156 }
157 
158 /*---------------------------------------------------------------
159  createDirectory
160  ---------------------------------------------------------------*/
161 bool mrpt::system::createDirectory(const string& dirName)
162 {
163 #ifdef _WIN32
164  bool rc = 0 != CreateDirectoryA(dirName.c_str(), nullptr);
165  return (rc || GetLastError() == ERROR_ALREADY_EXISTS);
166 #else
167  int ret = mkdir(dirName.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
168  if (ret && errno != EEXIST) // We ignore this error...
169  {
170  string str = format("[createDirectory %s]", dirName.c_str());
171  perror(str.c_str());
172  return false;
173  }
174  else
175  return true; // OK
176 #endif
177 }
178 
179 /*---------------------------------------------------------------
180  deleteFile
181  ---------------------------------------------------------------*/
182 bool mrpt::system::deleteFile(const string& fileName)
183 {
184  return 0 == remove(fileName.c_str());
185 }
186 
187 /*---------------------------------------------------------------
188  mrpt::system::deleteFiles
189 ---------------------------------------------------------------*/
190 void mrpt::system::deleteFiles(const string& s)
191 {
192  MRPT_START
193  size_t len = s.size() + 20;
194  std::vector<char> aux(len);
195 #ifdef _WIN32
196  os::sprintf(&aux[0], len, "del %s", &s[0]);
197  for (char* c = &aux[0]; *c; c++)
198  if (*c == '/') *c = '\\';
199  os::strcat(&aux[0], len, " /Q");
200 #else
201  os::sprintf(&aux[0], len, "rm %s", &s[0]);
202 #endif
203 
204  int res = ::system(&aux[0]);
205  if (res)
206  {
207  fprintf(
208  stderr,
209  "[mrpt::system::deleteFiles] Warning: error invoking: `%s`\n",
210  &aux[0]);
211  }
212  MRPT_END
213 }
214 
215 /*---------------------------------------------------------------
216  deleteFilesInDirectory
217 ---------------------------------------------------------------*/
219  const string& path, bool deleteDirectoryAsWell)
220 {
221  if (!directoryExists(path)) return false;
222 
225  path, FILE_ATTRIB_ARCHIVE | FILE_ATTRIB_DIRECTORY, lstFiles);
226 
227  for (auto& lstFile : lstFiles)
228  {
229  if (lstFile.isDir)
230  {
231  if (lstFile.name != "." && lstFile.name != "..")
232  {
234  lstFile.wholePath, true))
235  return false;
236  }
237  }
238  else
239  {
240  if (!mrpt::system::deleteFile(lstFile.wholePath)) return false;
241  }
242  }
243 
244  // Finally, delete the directory itselt.
245  if (deleteDirectoryAsWell)
246  return 0 == _rmdir(path.c_str());
247  else
248  return true;
249 }
250 
251 std::string mrpt::system::getcwd()
252 {
253  MRPT_START
254 
255 #ifdef _WIN32
256  char auxBuf[MAX_PATH] = "";
257  if (!::GetCurrentDirectoryA(sizeof(auxBuf) - 1, auxBuf))
258  THROW_EXCEPTION("Error getting current working directory!");
259  return std::string(auxBuf);
260 
261 #else
262  size_t size = 100;
263  for (;;)
264  {
265  std::string cwd;
266  cwd.resize(size);
267  if (::getcwd(&cwd[0], size) == &cwd[0])
268  {
269  return cwd;
270  }
271  if (errno != ERANGE)
272  THROW_EXCEPTION("Error getting current working directory!");
273  size *= 2;
274  }
275 #endif
276 
277  MRPT_END
278 }
279 
280 /*---------------------------------------------------------------
281  getTempFileName
282  ---------------------------------------------------------------*/
284 {
285 #ifdef _WIN32
286  FILETIME tt;
287  GetSystemTimeAsFileTime(&tt);
288  const UINT uniq = static_cast<UINT>(tt.dwLowDateTime);
289  char TMP_PATH[MAX_PATH];
290  char tmpPath[MAX_PATH];
291  GetTempPathA(MAX_PATH, tmpPath);
292  GetTempFileNameA(tmpPath, "mrpt", uniq, TMP_PATH);
293  return std::string(TMP_PATH);
294 #else
295  char tmp[] = "/tmp/mrpt_tempXXXXXX";
296  int fd;
297  fd = mkstemp(tmp);
298  ASSERT_(fd >= 0);
299  close(fd);
300  return std::string(tmp);
301 #endif
302 }
303 
304 /** Renames a file - If the target path is different and the filesystem allows
305  * it, it will be moved to the new location.
306  * \return false on any error. In that case, if a pointer to a receiver string
307  * is passed in error_msg, a description of the error is saved there.
308  */
310  const string& oldFileName, const string& newFileName,
311  std::string* error_msg)
312 {
313  bool ret_err = 0 == rename(oldFileName.c_str(), newFileName.c_str());
314 
315  if (error_msg)
316  {
317  if (ret_err)
318  *error_msg = strerror(errno);
319  else
320  *error_msg = "";
321  }
322 
323  return ret_err;
324 }
325 
326 /*---------------------------------------------------------------
327  fileNameStripInvalidChars
328 ---------------------------------------------------------------*/
330  const std::string& filename, const char replacement_to_invalid_chars)
331 {
332  const char forbid[] = {'<', '>', ':', '"', '/', '\\', '|', '?', '*'};
333  const unsigned int nForbid = sizeof(forbid) / sizeof(forbid[0]);
334 
335  string ret(filename);
336  for (char& c : ret)
337  {
338  bool invalid = (c < 32);
339 
340  for (unsigned int i = 0; !invalid && i < nForbid; i++)
341  if (c == forbid[i]) invalid = true;
342 
343  if (invalid) c = replacement_to_invalid_chars;
344  }
345  return ret;
346 }
347 
348 /*---------------------------------------------------------------
349  getFileSize
350 ---------------------------------------------------------------*/
351 uint64_t mrpt::system::getFileSize(const std::string& fileName)
352 {
353 #if defined(_MSC_VER)
354  // Visual Studio:
355  struct __stat64 filStat;
356  if (_stat64(fileName.c_str(), &filStat))
357  return uint64_t(-1);
358  else
359  return uint64_t(filStat.st_size);
360 #else
361  // The rest of the world:
362  struct stat filStat
363  {
364  };
365  if (stat(fileName.c_str(), &filStat))
366  return uint64_t(-1);
367  else
368  return uint64_t(filStat.st_size);
369 #endif
370 }
371 
372 /** Replace the filename extension by another one. */
374  const std::string& filePath, const std::string& newExtension)
375 {
376  if (filePath.size() < 2) return filePath;
377 
378  const size_t i_end = filePath.size() - 1;
379 
380  for (int i = int(i_end); i > 0; i--)
381  if (filePath[i] == '.') return filePath.substr(0, i + 1) + newExtension;
382 
383  // No extension found: add it:
384  return filePath + string(".") + newExtension;
385 }
386 
387 /*---------------------------------------------------------------
388  copyFile
389 ---------------------------------------------------------------*/
391  const std::string& sourceFile, const std::string& targetFile,
392  std::string* outErrStr, bool copyAttribs)
393 {
394  const std::string org =
396  const std::string trg =
398 
399  const bool fil_exs = fileExists(org);
400  const bool dir_exs = directoryExists(org);
401 
402  // Is source a directory?
403  if (!fil_exs)
404  {
405  if (outErrStr)
406  *outErrStr =
407  string("Source does not exist or permission denied!: ") + org;
408  return false;
409  }
410  if (dir_exs)
411  {
412  if (outErrStr) *outErrStr = string("Is source a directory?: ") + org;
413  return false;
414  }
415 
416  // Check if source file exists and we have access to open it:
417  FILE* f_src = fopen(org.c_str(), "rb");
418  if (!f_src)
419  {
420  if (outErrStr)
421  *outErrStr = string(
422  "Source file exists but cannot open it... is file "
423  "being used?: ") +
424  org;
425  return false;
426  }
427 
428  // Assure that "target" is not an existing directory:
429  if (directoryExists(trg))
430  {
431  if (outErrStr)
432  *outErrStr = string("Target cannot be a directory: ") + trg;
433  fclose(f_src);
434  return false;
435  }
436 
437  // Try to open the file for writting:
438  FILE* f_trg = fopen(trg.c_str(), "wb");
439  if (!f_trg)
440  {
441  if (!fileExists(trg))
442  {
443  // It does not exist and does not allow us to create it:
444  if (outErrStr)
445  *outErrStr = string("Cannot create target file: ") + trg;
446  fclose(f_src);
447  return false;
448  }
449  else
450  {
451  // It exists, but cannot overwrite it:
452 
453 #ifdef _WIN32
454  // Try changing the permissions of the target file:
455  DWORD dwProp = GetFileAttributesA(trg.c_str());
456  if (dwProp == INVALID_FILE_ATTRIBUTES)
457  {
458  if (outErrStr)
459  *outErrStr =
460  string(
461  "Cannot get file attributes for target file, "
462  "trying to remove a possible read-only attribute "
463  "after first attempt of copy failed, for: ") +
464  trg;
465  fclose(f_src);
466  return false;
467  }
468 
469  dwProp &= ~FILE_ATTRIBUTE_HIDDEN;
470  dwProp &= ~FILE_ATTRIBUTE_READONLY;
471  dwProp &= ~FILE_ATTRIBUTE_SYSTEM;
472 
473  if (!SetFileAttributesA(trg.c_str(), dwProp))
474  {
475  if (outErrStr)
476  *outErrStr =
477  string(
478  "Cannot get file attributes for target file, "
479  "trying to remove a possible read-only attribute "
480  "after first attempt of copy failed, for: ") +
481  trg;
482  fclose(f_src);
483  return false;
484  }
485 
486  // Try again:
487  f_trg = fopen(trg.c_str(), "wb");
488  if (!f_trg)
489  {
490  if (outErrStr)
491  *outErrStr = string(
492  "Cannot overwrite target file, even after "
493  "changing file attributes! : ") +
494  trg;
495  fclose(f_src);
496  return false;
497  }
498 #else
499  // Try changing the permissions of the target file:
500  if (chmod(trg.c_str(), S_IRWXU | S_IRGRP | S_IROTH))
501  {
502  if (outErrStr)
503  *outErrStr =
504  string(
505  "Cannot set file permissions for target file, "
506  "trying to remove a possible read-only attribute "
507  "after first attempt of copy failed, for: ") +
508  trg;
509  fclose(f_src);
510  return false;
511  }
512 
513  // Try again:
514  f_trg = fopen(trg.c_str(), "wb");
515  if (!f_trg)
516  {
517  if (outErrStr)
518  *outErrStr = string(
519  "Cannot overwrite target file, even after "
520  "changing file permissions! : ") +
521  trg;
522  fclose(f_src);
523  return false;
524  }
525 #endif
526  }
527  }
528 
529  // Ok, here we have both files open: Perform the copy:
530  char buf[66000];
531  size_t nBytes = 0;
532  while (0 != (nBytes = fread(buf, 1, 64 * 1024, f_src)))
533  {
534  if (nBytes != fwrite(buf, 1, nBytes, f_trg))
535  {
536  if (outErrStr)
537  *outErrStr = string(
538  "Error writing the contents of the target "
539  "file (disk full?): ") +
540  trg;
541  fclose(f_src);
542  fclose(f_trg);
543  return false;
544  }
545  }
546 
547  // Close file handles:
548  fclose(f_src);
549  fclose(f_trg);
550 
551  // In Windows only, copy the file attributes:
552  if (copyAttribs)
553  {
554 #ifdef _WIN32
555  DWORD dwPropSrc = GetFileAttributesA(org.c_str());
556  if (dwPropSrc == INVALID_FILE_ATTRIBUTES)
557  {
558  if (outErrStr)
559  *outErrStr =
560  string(
561  "Cannot get the file attributes for source file: ") +
562  org;
563  return false;
564  }
565  DWORD dwPropTrg = GetFileAttributesA(trg.c_str());
566  if (dwPropTrg == INVALID_FILE_ATTRIBUTES)
567  {
568  if (outErrStr)
569  *outErrStr =
570  string(
571  "Cannot get the file attributes for target file: ") +
572  trg;
573  return false;
574  }
575 
576  // Leave only those attributes which can be legally copied:
577  // (Refer to: http://msdn2.microsoft.com/en-us/library/aa365535.aspx )
578  dwPropSrc &= FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN |
579  FILE_ATTRIBUTE_NORMAL |
580  FILE_ATTRIBUTE_NOT_CONTENT_INDEXED |
581  FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_READONLY |
582  FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_TEMPORARY;
583 
584  // Copy them to the target attributes:
585  dwPropTrg &=
586  ~(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN |
587  FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED |
588  FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_READONLY |
589  FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_TEMPORARY);
590  dwPropTrg |= dwPropSrc;
591 
592  // Set attributes of target file:
593  if (!SetFileAttributesA(trg.c_str(), dwPropTrg))
594  {
595  if (outErrStr)
596  *outErrStr =
597  string("Cannot set file attributes for target file: ") +
598  trg;
599  return false;
600  }
601 #else
602 // Linux: No file attributes to copy.
603 #endif
604  } // end // if (copyAttribs)
605 
606  return true;
607 }
608 
609 // ---------------------------------------------------------------
610 // filePathSeparatorsToNative
611 // ---------------------------------------------------------------
613  const std::string& filePath)
614 {
615  std::string ret = filePath;
616  const size_t N = ret.size();
617  for (size_t i = 0; i < N; i++)
618  {
619 #ifdef _WIN32
620  if (ret[i] == '/') ret[i] = '\\';
621 #else
622  if (ret[i] == '\\') ret[i] = '/';
623 #endif
624  }
625  return ret;
626 }
627 
628 time_t mrpt::system::getFileModificationTime(const std::string& filename)
629 {
630  struct stat fS
631  {
632  };
633  if (0 != stat(filename.c_str(), &fS))
634  return 0;
635  else
636  return fS.st_mtime;
637 }
638 
639 #include <mrpt/version.h>
640 // Read docs in .h
642 {
643  using std::string;
644  using std::vector;
645 
646  static vector<string> sPaths;
647  static string sDetectedPath;
648  static bool is_first = true;
649  if (is_first)
650  {
651  is_first = false;
652 
653  // Source dir:
654  sPaths.push_back(
655  string(MRPT_CMAKE_SOURCE_DIR) + string("/share/mrpt/"));
656  // Install dir:
657  sPaths.push_back(
658  string(MRPT_CMAKE_INSTALL_PREFIX) + string("/share/mrpt/"));
659 
660  // Program path & ".." & "../..":
661  char buf[2048];
662  bool sBufOk = false;
663 #ifdef _WIN32
664  sBufOk = (0 != GetModuleFileNameA(NULL, buf, sizeof(buf)));
665 #endif
666 #ifdef MRPT_OS_LINUX
667  ssize_t nRead = readlink("/proc/self/exe", buf, sizeof(buf));
668  if (nRead >= 0) buf[nRead] = '\0';
669  sBufOk = (-1 != nRead);
670 #endif
671 
672  if (sBufOk)
673  {
674  string sBuf = string(buf);
675  std::replace(sBuf.begin(), sBuf.end(), '\\', '/');
676  sBuf = extractFileDirectory(sBuf);
677  sPaths.push_back(sBuf + string("share/mrpt/"));
678  sPaths.push_back(sBuf + string("../share/mrpt/"));
679  sPaths.push_back(sBuf + string("../../share/mrpt/"));
680  }
681 
682  for (const auto& e : sPaths)
683  if (directoryExists(e))
684  {
685  sDetectedPath = e;
686  break;
687  }
688  }
689  return sDetectedPath;
690 }
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...
bool createDirectory(const std::string &dirName)
Creates a directory.
Definition: filesystem.cpp:161
#define MRPT_START
Definition: exceptions.h:241
#define _stat
Definition: filesystem.cpp:49
std::string getShareMRPTDir()
Attempts to find the directory [PREFIX/]share/mrpt/ and returns its absolute path, or empty string if not found.
Definition: filesystem.cpp:641
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
size_t size(const MATRIXLIKE &m, const int dim)
std::deque< TFileInfo > TFileInfoList
The list type used in "explore".
int void fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:286
char * strcat(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcat.
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:128
bool renameFile(const std::string &oldFileName, const std::string &newFileName, std::string *error_msg=nullptr)
Renames a file - If the target path is different and the filesystem allows it, it will be moved to th...
Definition: filesystem.cpp:309
STL namespace.
std::string fileNameStripInvalidChars(const std::string &filename, const char replacement_to_invalid_chars='_')
Replace invalid filename chars by underscores (&#39;_&#39;) or any other user-given char. ...
Definition: filesystem.cpp:329
#define FILE_ATTRIB_ARCHIVE
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
std::string getTempFileName()
Returns the name of a proposed temporary file name.
Definition: filesystem.cpp:283
std::string filePathSeparatorsToNative(const std::string &filePath)
Windows: replace all &#39;/&#39;->&#39;\&#39; , in Linux/MacOS: replace all &#39;\&#39;->&#39;/&#39;.
Definition: filesystem.cpp:612
std::string fileNameChangeExtension(const std::string &filename, const std::string &newExtension)
Replace the filename extension by another one.
Definition: filesystem.cpp:373
void deleteFiles(const std::string &s)
Delete one or more files, especified by the (optional) path and the file name (including &#39;...
Definition: filesystem.cpp:190
#define _rmdir
Definition: filesystem.cpp:47
std::string extractFileExtension(const std::string &filePath, bool ignore_gz=false)
Extract the extension of a filename.
Definition: filesystem.cpp:98
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
Definition: os.cpp:419
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define FILE_ATTRIB_DIRECTORY
std::string getcwd()
Returns the current working directory.
Definition: filesystem.cpp:251
#define MRPT_END
Definition: exceptions.h:245
#define _access
Definition: filesystem.cpp:46
bool deleteFile(const std::string &fileName)
Deletes a single file.
Definition: filesystem.cpp:182
bool copyFile(const std::string &sourceFile, const std::string &targetFile, std::string *outErrStr=nullptr, bool copyAttribs=true)
Copies file sourceFile to targetFile.
Definition: filesystem.cpp:390
bool deleteFilesInDirectory(const std::string &s, bool deleteDirectoryAsWell=false)
Delete all the files in a given directory (nothing done if directory does not exists, or path is a file).
Definition: filesystem.cpp:218
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
Definition: os.cpp:268
bool directoryExists(const std::string &fileName)
Test if a given directory exists (it fails if the given path refers to an existing file)...
Definition: filesystem.cpp:137
uint64_t getFileSize(const std::string &fileName)
Return the size of the given file, or size_t(-1) if some error is found accessing that file...
Definition: filesystem.cpp:351
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
std::string extractFileDirectory(const std::string &filePath)
Extract the whole path (the directory) of a filename from a complete path plus name plus extension...
Definition: filesystem.cpp:78
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
time_t getFileModificationTime(const std::string &filename)
Return the time of the file last modification, or "0" if the file doesn&#39;t exist.
Definition: filesystem.cpp:628



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020