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



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019