Visual Servoing Platform  version 3.6.1 under development (2025-03-10)
vpIoTools.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Directory management.
32  */
33 
39 // At this point, to make scandir() working as expected on armv7 virtualized on a x86-64bit architecture
40 // (see github/workflow/other-arch-isolated.yml) we need to define _FILE_OFFSET_BITS=64. Otherwise
41 // testVideo.cpp will fail.
42 // Since adding here something like:
43 // #include <visp3/core/vpConfig.h>
44 // #ifdef VISP_DEFINE_FILE_OFFSET_BITS
45 // # define _FILE_OFFSET_BITS 64
46 // #endif
47 // where VISP_DEFINE_FILE_OFFSET_BITS is defined in vpConfig.h doesn't work (my explanation is that the define
48 // should be done before any other includes; in vpConfig.h there is cstdlib that is included), the other way
49 // that was retained is to add to vpIoTools.cpp COMPILE_DEFINTIONS _FILE_OFFSET_BITS=64 (see CMakeLists.txt)
50 
51 #include <algorithm>
52 #include <cctype>
53 #include <cmath>
54 #include <errno.h>
55 #include <fcntl.h>
56 #include <fstream>
57 #include <functional>
58 #include <limits> // numeric_limits
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <sys/stat.h>
63 #include <sys/types.h>
64 #include <visp3/core/vpEndian.h>
65 #include <visp3/core/vpIoException.h>
66 #include <visp3/core/vpIoTools.h>
67 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
68 #include <dirent.h>
69 #include <unistd.h>
70 #elif defined(_WIN32)
71 #include <direct.h>
72 #include <windows.h>
73 #endif
74 #if !defined(_WIN32)
75 #ifdef __ANDROID__
76 // Like IOS, wordexp.cpp is not defined for Android
77 #else
78 #include <wordexp.h>
79 #endif
80 #endif
81 
82 #if defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin)
83 #include <TargetConditionals.h> // To detect OSX or IOS using TARGET_OS_IOS macro
84 #endif
85 
86 #ifndef PATH_MAX
87 #ifdef _MAX_PATH
88 #define PATH_MAX _MAX_PATH
89 #else
90 #define PATH_MAX 1024
91 #endif
92 #endif
93 
94 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
95 #define VP_STAT stat
96 #elif defined(_WIN32) && defined(__MINGW32__)
97 #define VP_STAT stat
98 #elif defined(_WIN32)
99 #define VP_STAT _stat
100 #else
101 #define VP_STAT stat
102 #endif
103 namespace
104 {
105 // The following code is not working on iOS since wordexp() is not available
106 // The function is not used on Android
107 #if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
108 #if (TARGET_OS_IOS == 0) && !defined(__ANDROID__)
109 void replaceAll(std::string &str, const std::string &search, const std::string &replace)
110 {
111  size_t start_pos = 0;
112  while ((start_pos = str.find(search, start_pos)) != std::string::npos) {
113  str.replace(start_pos, search.length(), replace);
114  start_pos += replace.length(); // Handles case where 'replace' is a
115  // substring of 'search'
116  }
117 }
118 #endif
119 #endif
120 } // namespace
121 
122 BEGIN_VISP_NAMESPACE
126  const std::string &vpIoTools::getBuildInformation()
127 {
128  static std::string build_info =
129 #include "version_string.inc"
130  ;
131  return build_info;
132 }
133 
190 {
191 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
192  std::string username;
193  vpIoTools::getUserName(username);
194  return "/tmp/" + username;
195 #elif defined(_WIN32) && !defined(WINRT)
196  // https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-using-a-temporary-file
197  // Gets the temp path env string (no guarantee it's a valid path).
198  TCHAR lpTempPathBuffer[MAX_PATH];
199  DWORD dwRetVal = GetTempPath(MAX_PATH /* length of the buffer */, lpTempPathBuffer /* buffer for path */);
200  if (dwRetVal > MAX_PATH || (dwRetVal == 0)) {
201  throw vpIoException(vpIoException::cantGetenv, "Error with GetTempPath() call!");
202  }
203  std::string temp_path(lpTempPathBuffer);
204  if (!temp_path.empty()) {
205  if (temp_path.back() == '\\') {
206  temp_path.resize(temp_path.size() - 1);
207  }
208  }
209  else {
210  temp_path = "C:\temp";
211  try {
212  vpIoTools::makeDirectory(temp_path);
213  }
214  catch (...) {
215  throw(vpException(vpException::fatalError, "Cannot set temp path to %s", temp_path.c_str()));
216  }
217  }
218  return temp_path;
219 #else
220  throw vpIoException(vpException::fatalError, "Not implemented on this platform!");
221 #endif
222 }
223 
237 void vpIoTools::getUserName(std::string &username)
238 {
239  // With MinGW, UNIX and _WIN32 are defined
240 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
241  // Get the user name.
242  char *logname = ::getenv("LOGNAME");
243  if (!logname) {
244  username = "unknown";
245  }
246  else {
247  username = logname;
248  }
249 #elif defined(_WIN32)
250 #if (!defined(WINRT))
251  unsigned int info_buffer_size = 1024;
252  TCHAR *infoBuf = new TCHAR[info_buffer_size];
253  DWORD bufCharCount = (DWORD)info_buffer_size;
254  // Get the user name.
255  if (!GetUserName(infoBuf, &bufCharCount)) {
256  username = "unknown";
257  }
258  else {
259  username = infoBuf;
260  }
261  delete[] infoBuf;
262 #else
263  // Universal platform
264  username = "unknown";
265 #endif
266 #else
267  username = "unknown";
268 #endif
269 }
270 
286 {
287  std::string username;
288  getUserName(username);
289  return username;
290 }
291 
326 std::string vpIoTools::getenv(const std::string &env)
327 {
328 #if defined(_WIN32) && defined(WINRT)
329  throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value: not "
330  "implemented on Universal Windows Platform"));
331 #else
332  std::string value;
333  // Get the environment variable value.
334  char *v_value = ::getenv(env.c_str());
335  if (!v_value) {
336  throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value"));
337  }
338  value = v_value;
339 
340  return value;
341 #endif
342 }
343 
353 void vpIoTools::getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
354 {
355  if (version.size() == 0) {
356  major = 0;
357  minor = 0;
358  patch = 0;
359  }
360  else {
361  size_t major_pos = version.find('.');
362  std::string major_str = version.substr(0, major_pos);
363  major = static_cast<unsigned>(atoi(major_str.c_str()));
364 
365  if (major_pos != std::string::npos) {
366  size_t minor_pos = version.find('.', major_pos + 1);
367  std::string minor_str = version.substr(major_pos + 1, (minor_pos - (major_pos + 1)));
368  minor = static_cast<unsigned>(atoi(minor_str.c_str()));
369 
370  if (minor_pos != std::string::npos) {
371  std::string patch_str = version.substr(minor_pos + 1);
372  patch = static_cast<unsigned>(atoi(patch_str.c_str()));
373  }
374  else {
375  patch = 0;
376  }
377  }
378  else {
379  minor = 0;
380  patch = 0;
381  }
382  }
383 }
384 
396 bool vpIoTools::checkDirectory(const std::string &dirname)
397 {
398 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
399  struct stat stbuf;
400 #elif defined(_WIN32) && defined(__MINGW32__)
401  struct stat stbuf;
402 #elif defined(_WIN32)
403  struct _stat stbuf;
404 #endif
405 
406  if (dirname.empty()) {
407  return false;
408  }
409 
410  std::string path_dirname = path(dirname);
411 
412  if (VP_STAT(path_dirname.c_str(), &stbuf) != 0) {
413  // Test adding the separator if not already present
414  if (path_dirname.at(path_dirname.size() - 1) != separator) {
415  if (VP_STAT((path_dirname + separator).c_str(), &stbuf) != 0) {
416  return false;
417  }
418  }
419  // Test removing the separator if already present
420  if (path_dirname.at(path_dirname.size() - 1) == separator) {
421  if (VP_STAT((path_dirname.substr(0, path_dirname.size() - 1)).c_str(), &stbuf) != 0) {
422  return false;
423  }
424  }
425  }
426 
427 #if defined(_WIN32) || (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
428  if ((stbuf.st_mode & S_IFDIR) == 0)
429 #endif
430  {
431  return false;
432  }
433 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
434  if ((stbuf.st_mode & S_IWUSR) == 0)
435 #elif defined(_WIN32)
436  if ((stbuf.st_mode & S_IWRITE) == 0)
437 #endif
438  {
439  return false;
440  }
441  return true;
442 }
443 
456 bool vpIoTools::checkFifo(const std::string &fifofilename)
457 {
458 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
459  struct stat stbuf;
460 
461  std::string v_filename = path(fifofilename);
462  if (stat(v_filename.c_str(), &stbuf) != 0) {
463  return false;
464  }
465  if ((stbuf.st_mode & S_IFIFO) == 0) {
466  return false;
467  }
468  if ((stbuf.st_mode & S_IRUSR) == 0)
469 
470  {
471  return false;
472  }
473  return true;
474 #elif defined(_WIN32)
475  (void)fifofilename;
476  throw(vpIoException(vpIoException::notImplementedError, "Fifo files are not supported on Windows platforms."));
477 #endif
478 }
479 
480 #ifndef DOXYGEN_SHOULD_SKIP_THIS
481 int vpIoTools::mkdir_p(const std::string &path, int mode)
482 {
483  errno = 0;
484  if (path.size() > PATH_MAX) {
485  errno = ENAMETOOLONG;
486  return -1;
487  }
488 
489  // Iterate over the string
490  std::string cpy_path = path;
491  std::string sub_path;
492  size_t pos = 0;
493  while (pos != std::string::npos) {
494  sub_path += cpy_path.substr(0, pos + 1);
495  // Continue if sub_path = separator
496  bool stop_for_loop = false;
497  if (pos == 0) {
498  cpy_path.erase(0, pos + 1);
499  stop_for_loop = true;
500  }
501  if (!stop_for_loop) {
502 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
503  if (mkdir(sub_path.c_str(), static_cast<mode_t>(mode)) != 0)
504 #elif defined(_WIN32)
505  (void)mode; // var not used
506  if (!checkDirectory(sub_path) && _mkdir(sub_path.c_str()) != 0)
507 #endif
508  {
509  if (errno != EEXIST) {
510  return -1;
511  }
512  }
513  cpy_path.erase(0, pos + 1);
514  }
515  pos = cpy_path.find(vpIoTools::separator);
516  }
517 
518  if (!cpy_path.empty()) {
519  sub_path += cpy_path;
520 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
521  if (mkdir(sub_path.c_str(), static_cast<mode_t>(mode)) != 0)
522 #elif defined(_WIN32)
523 
524  if (_mkdir(sub_path.c_str()) != 0)
525 #endif
526  {
527  if (errno != EEXIST) {
528  return -1;
529  }
530  }
531  }
532 
533  return 0;
534 }
535 
536 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
537 
550 void vpIoTools::makeDirectory(const std::string &dirname)
551 {
552 #if ((!defined(__unix__) && !defined(__unix) && (!defined(__APPLE__) || !defined(__MACH__)))) && !defined(_WIN32)
553  std::cerr << "Unsupported platform for vpIoTools::makeDirectory()!" << std::endl;
554  return;
555 #endif
556 
557 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
558  struct stat stbuf;
559 #elif defined(_WIN32) && defined(__MINGW32__)
560  struct stat stbuf;
561 #elif defined(_WIN32)
562  struct _stat stbuf;
563 #endif
564 
565  if (dirname.empty()) {
566  throw(vpIoException(vpIoException::invalidDirectoryName, "invalid directory name"));
567  }
568 
569  std::string v_dirname = path(dirname);
570 
571 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
572  if (stat(v_dirname.c_str(), &stbuf) != 0)
573 #elif defined(_WIN32) && defined(__MINGW32__)
574  if (stat(v_dirname.c_str(), &stbuf) != 0)
575 #elif defined(_WIN32)
576  if (_stat(v_dirname.c_str(), &stbuf) != 0)
577 #endif
578  {
579  if (vpIoTools::mkdir_p(v_dirname, 0755) != 0) {
580  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str()));
581  }
582  }
583 
584  if (checkDirectory(dirname) == false) {
585  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str()));
586  }
587 }
588 
601 void vpIoTools::makeFifo(const std::string &fifoname)
602 {
603 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
604 
605  // If dirname is a directory, we throw an error
606  if (vpIoTools::checkDirectory(fifoname)) {
608  "Unable to create fifo file. '%s' is an existing directory.", fifoname.c_str()));
609  }
610 
611  // If dirname refers to an already existing file, we throw an error
612  else if (vpIoTools::checkFilename(fifoname)) {
613  throw(vpIoException(vpIoException::invalidDirectoryName, "Unable to create fifo file '%s'. File already exists.",
614  fifoname.c_str()));
615  // If dirname refers to an already existing fifo, we throw an error
616  }
617  else if (vpIoTools::checkFifo(fifoname)) {
618  throw(vpIoException(vpIoException::invalidDirectoryName, "Unable to create fifo file '%s'. Fifo already exists.",
619  fifoname.c_str()));
620  }
621 
622  else if (mkfifo(fifoname.c_str(), 0666) < 0) {
623  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create fifo file '%s'.", fifoname.c_str()));
624  }
625 #elif defined(_WIN32)
626  (void)fifoname;
627  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create fifo on Windows platforms."));
628 #endif
629 }
630 
631 #if defined(_WIN32) && !defined(WINRT)
632 std::string getUuid()
633 {
634  UUID uuid;
635  if (UuidCreate(&uuid) != RPC_S_OK) {
636  throw(vpIoException(vpIoException::fatalError, "UuidCreate() failed!"));
637  }
638 
639  RPC_CSTR stringUuid;
640  if (UuidToString(&uuid, &stringUuid) != RPC_S_OK) {
641  throw(vpIoException(vpIoException::fatalError, "UuidToString() failed!"));
642  }
643 
644  return reinterpret_cast<char *>(stringUuid);
645 }
646 #endif
647 
708 std::string vpIoTools::makeTempDirectory(const std::string &dirname)
709 {
710 #if defined(WINRT) || !defined(_WIN32) && !(defined(__unix__) || defined(__unix) || \
711  (defined(__APPLE__) && defined(__MACH__))) // not UNIX and not Windows
712  throw(vpIoException(vpIoException::cantCreateDirectory, "makeTempDirectory() is not supported on this platform!"));
713 #endif
714 
715  std::string dirname_cpy = std::string(dirname);
716  std::string correctEnding = "XXXXXX";
717 
718  // If dirname is an unexisting directory, it should end with XXXXXX in order to create a temp directory
719  if (!vpIoTools::checkDirectory(dirname_cpy)) {
720 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
721  // Check if dirname ends with XXXXXX
722  if (dirname_cpy.rfind(correctEnding) == std::string::npos) {
723  if (dirname_cpy.at(dirname_cpy.length() - 1) != '/') {
724  dirname_cpy = dirname_cpy + "/";
725  }
726  try {
727  vpIoTools::makeDirectory(dirname_cpy);
728  }
729  catch (...) {
730  throw(vpException(vpException::fatalError, "Cannot create temp directory %s", dirname_cpy.c_str()));
731  }
732 
733  dirname_cpy = dirname_cpy + "XXXXXX";
734  }
735 
736 #elif defined(_WIN32) && !defined(WINRT)
737  // Remove XXXXXX
738  dirname_cpy = dirname_cpy.substr(0, dirname_cpy.rfind(correctEnding));
739  // Append UUID
740  dirname_cpy = dirname_cpy + getUuid();
741 #endif
742 
743  }
744  else {
745  // If dirname is an existing directory, we create a temp directory inside
746 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
747  if (dirname_cpy.at(dirname_cpy.length() - 1) != '/') {
748  dirname_cpy = dirname_cpy + "/";
749  }
750  dirname_cpy = dirname_cpy + "XXXXXX";
751 #elif defined(_WIN32) && !defined(WINRT)
752  dirname_cpy = createFilePath(dirname_cpy, getUuid());
753 #endif
754  }
755 
756 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
757  char *dirname_char = new char[dirname_cpy.length() + 1];
758  strcpy(dirname_char, dirname_cpy.c_str());
759 
760  char *computedDirname = mkdtemp(dirname_char);
761 
762  if (!computedDirname) {
763  delete[] dirname_char;
764  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'.", dirname_cpy.c_str()));
765  }
766 
767  std::string res(computedDirname);
768  delete[] dirname_char;
769  return res;
770 #elif defined(_WIN32) && !defined(WINRT)
771  makeDirectory(dirname_cpy);
772  return dirname_cpy;
773 #endif
774 }
775 
786 bool vpIoTools::checkFilename(const std::string &filename)
787 {
788 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
789  struct stat stbuf;
790 #elif defined(_WIN32)
791  struct _stat stbuf;
792 #endif
793 
794  if (filename.empty()) {
795  return false;
796  }
797 
798  std::string v_filename = path(filename);
799 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
800  if (stat(v_filename.c_str(), &stbuf) != 0)
801 #elif defined(_WIN32)
802  if (_stat(v_filename.c_str(), &stbuf) != 0)
803 #endif
804  {
805  return false;
806  }
807  if ((stbuf.st_mode & S_IFREG) == 0) {
808  return false;
809  }
810 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
811  if ((stbuf.st_mode & S_IRUSR) == 0)
812 #elif defined(_WIN32)
813  if ((stbuf.st_mode & S_IREAD) == 0)
814 #endif
815  {
816  return false;
817  }
818  return true;
819 }
820 
828 bool vpIoTools::copy(const std::string &src, const std::string &dst)
829 {
830  // Check if we have to consider a file or a directory
831  if (vpIoTools::checkFilename(src)) {
832  // --comment: std::cout "copy file: " src " in " dst std::endl;
833 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
834 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
835  // wordexp() is not available
836  std::stringstream cmd;
837  cmd << "cp -p ";
838  cmd << src;
839  cmd << " ";
840  cmd << dst;
841  int ret = system(cmd.str().c_str());
842  if (ret) {
843  } // to avoid a warning
844  // std::cout << cmd << " return value: " << ret << std::endl;
845  return true;
846 #else
847  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src.c_str(),
848  dst.c_str()));
849 #endif
850 #elif defined(_WIN32)
851 #if (!defined(WINRT))
852  std::stringstream cmd;
853  cmd << "copy ";
854  cmd << vpIoTools::path(src);
855  cmd << " ";
856  cmd << vpIoTools::path(dst);
857  int ret = system(cmd.str().c_str());
858  if (ret) {
859  }; // to avoid a warning
860  // std::cout << cmd << " return value: " << ret << std::endl;
861  return true;
862 #else
863  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
864  src.c_str(), dst.c_str()));
865 #endif
866 #endif
867  }
868  else if (vpIoTools::checkDirectory(src)) {
869  // --comment: std::cout "copy directory: " src " in " dst
870 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
871 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
872  // wordexp() is not available
873  std::stringstream cmd;
874  cmd << "cp -p ";
875  cmd << src;
876  cmd << " ";
877  cmd << dst;
878  int ret = system(cmd.str().c_str());
879  if (ret) {
880  } // to avoid a warning
881  // std::cout << cmd << " return value: " << ret << std::endl;
882  return true;
883 #else
884  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src.c_str(),
885  dst.c_str()));
886 #endif
887 #elif defined(_WIN32)
888 #if (!defined(WINRT))
889  std::stringstream cmd;
890  cmd << "copy ";
891  cmd << vpIoTools::path(src);
892  cmd << " ";
893  cmd << vpIoTools::path(dst);
894  int ret = system(cmd.str().c_str());
895  if (ret) {
896  }; // to avoid a warning
897  // std::cout << cmd << " return value: " << ret << std::endl;
898  return true;
899 #else
900  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
901  src.c_str(), dst.c_str()));
902 #endif
903 #endif
904  }
905  else {
906  std::cout << "Cannot copy: " << src << " in " << dst << std::endl;
907  return false;
908  }
909 }
910 
921 bool vpIoTools::remove(const std::string &file_or_dir)
922 {
923  // Check if we have to consider a file or a directory
924  if (vpIoTools::checkFilename(file_or_dir)
925 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
926  || vpIoTools::checkFifo(std::string(file_or_dir))
927 #endif
928  ) {
929  if (::remove(file_or_dir.c_str()) != 0) {
930  return false;
931  }
932  else {
933  return true;
934  }
935  }
936  else if (vpIoTools::checkDirectory(file_or_dir)) {
937 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
938 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
939  // wordexp() is not available
940  std::stringstream cmd;
941  cmd << "rm -rf \"";
942  cmd << file_or_dir;
943  cmd << "\"";
944  int ret = system(cmd.str().c_str());
945  if (ret) {
946  } // to avoid a warning
947  // std::cout << cmd << " return value: " << ret << std::endl;
948  return true;
949 #else
950  throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on iOS Platform",
951  file_or_dir.c_str()));
952 #endif
953 #elif defined(_WIN32)
954 #if (!defined(WINRT))
955  std::stringstream cmd;
956  cmd << "rmdir /S /Q ";
957  cmd << vpIoTools::path(file_or_dir);
958  cmd << "\"";
959  int ret = system(cmd.str().c_str());
960  if (ret) {
961  }; // to avoid a warning
962  // std::cout << cmd << " return value: " << ret << std::endl;
963  return true;
964 #else
965  throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on Universal Windows Platform",
966  file_or_dir.c_str()));
967 #endif
968 #endif
969  }
970  else {
971  std::cout << "Cannot remove: " << file_or_dir << std::endl;
972  return false;
973  }
974 }
975 
985 bool vpIoTools::rename(const std::string &oldfilename, const std::string &newfilename)
986 {
987  if (::rename(oldfilename.c_str(), newfilename.c_str()) != 0) {
988  return false;
989  }
990  else {
991  return true;
992  }
993 }
994 
1005 std::string vpIoTools::path(const std::string &pathname)
1006 {
1007  std::string path(pathname);
1008 
1009 #if defined(_WIN32)
1010  for (unsigned int i = 0; i < path.length(); ++i)
1011  if (path[i] == '/')
1012  path[i] = '\\';
1013 #elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
1014  unsigned int path_length = path.length();
1015  for (unsigned int i = 0; i < path_length; ++i) {
1016  if (path[i] == '\\') {
1017  path[i] = '/';
1018  }
1019  }
1020 #if TARGET_OS_IOS == 0 // The following code is not working on iOS and android since
1021  // wordexp() is not available
1022 #ifdef __ANDROID__
1023 // Do nothing
1024 #else
1025  wordexp_t exp_result;
1026 
1027  // escape quote character
1028  replaceAll(path, "'", "'\\''");
1029  // add quotes to handle special characters like parentheses and spaces
1030  wordexp(std::string("'" + path + "'").c_str(), &exp_result, 0);
1031  path = exp_result.we_wordc == 1 ? exp_result.we_wordv[0] : "";
1032  wordfree(&exp_result);
1033 #endif
1034 #endif
1035 #endif
1036 
1037  return path;
1038 }
1039 
1054 {
1055  std::string data_path;
1056  std::string file_to_test("mbt/cube.cao");
1057  std::string filename;
1058  // Test if VISP_INPUT_IMAGE_PATH env var is set
1059  try {
1060  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH");
1061  filename = data_path + "/" + file_to_test;
1062  if (vpIoTools::checkFilename(filename)) {
1063  return data_path;
1064  }
1065  }
1066  catch (...) {
1067  }
1068  try {
1069  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/ViSP-images";
1070  filename = data_path + "/" + file_to_test;
1071  if (vpIoTools::checkFilename(filename)) {
1072  return data_path;
1073  }
1074  }
1075  catch (...) {
1076  }
1077  try {
1078  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/visp-images";
1079  filename = data_path + "/" + file_to_test;
1080  if (vpIoTools::checkFilename(filename)) {
1081  return data_path;
1082  }
1083  }
1084  catch (...) {
1085  }
1086 
1087 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1088  // Test if visp-images-data package is installed (Ubuntu and Debian)
1089  data_path = "/usr/share/visp-images-data/ViSP-images";
1090  filename = data_path + "/" + file_to_test;
1091  if (vpIoTools::checkFilename(filename)) {
1092  return data_path;
1093  }
1094  data_path = "/usr/share/visp-images-data/visp-images";
1095  filename = data_path + "/" + file_to_test;
1096  if (vpIoTools::checkFilename(filename)) {
1097  return data_path;
1098  }
1099 #endif
1100  data_path = "";
1101  return data_path;
1102 }
1103 
1136 std::string vpIoTools::getFileExtension(const std::string &pathname, bool checkFile)
1137 {
1138  if (checkFile && (vpIoTools::checkDirectory(pathname) || (!vpIoTools::checkFilename(pathname)))) {
1139  return "";
1140  }
1141 
1142 #if defined(_WIN32)
1143  std::string sep = "\\";
1144  std::string altsep = "/";
1145  std::string extsep = ".";
1146 #else
1147  // On Unix, or on the Mac
1148  std::string sep = "/";
1149  std::string altsep = "";
1150  std::string extsep = ".";
1151 #endif
1152 
1153  // Python 2.7.8 module.
1154  // # Split a path in root and extension.
1155  // # The extension is everything starting at the last dot in the last
1156  // # pathname component; the root is everything before that.
1157  // # It is always true that root + ext == p.
1158  //
1159  // # Generic implementation of splitext, to be parametrized with
1160  // # the separators
1161  // def _splitext(p, sep, altsep, extsep):
1162  // """Split the extension from a pathname.
1163  //
1164  // Extension is everything from the last dot to the end, ignoring
1165  // leading dots. Returns "(root, ext)"; ext may be empty."""
1166  //
1167  // sepIndex = p.rfind(sep)
1168  // if altsep:
1169  // altsepIndex = p.rfind(altsep)
1170  // sepIndex = max(sepIndex, altsepIndex)
1171  //
1172  // dotIndex = p.rfind(extsep)
1173  // if dotIndex > sepIndex:
1174  // # skip all leading dots
1175  // filenameIndex = sepIndex + 1
1176  // while filenameIndex < dotIndex:
1177  // if p[filenameIndex] != extsep:
1178  // return p[:dotIndex], p[dotIndex:]
1179  // filenameIndex += 1
1180  //
1181  // return p, ''
1182 
1183  int sepIndex = static_cast<int>(pathname.rfind(sep));
1184  if (!altsep.empty()) {
1185  int altsepIndex = static_cast<int>(pathname.rfind(altsep));
1186  sepIndex = std::max<int>(sepIndex, altsepIndex);
1187  }
1188 
1189  size_t dotIndex = pathname.rfind(extsep);
1190  if (dotIndex != std::string::npos) {
1191  // The extsep character exists
1192  size_t npos = std::string::npos;
1193  if (((sepIndex != static_cast<int>(npos)) && (static_cast<int>(dotIndex) > sepIndex)) ||
1194  (sepIndex == static_cast<int>(npos))) {
1195  if (sepIndex == static_cast<int>(npos)) {
1196  sepIndex = 0;
1197  }
1198  size_t filenameIndex = static_cast<size_t>(sepIndex) + static_cast<size_t>(1);
1199 
1200  while (filenameIndex < dotIndex) {
1201  if (pathname.compare(filenameIndex, 1, extsep) != 0) {
1202  return pathname.substr(dotIndex);
1203  }
1204  filenameIndex++;
1205  }
1206  }
1207  }
1208 
1209  return "";
1210 }
1211 
1217 std::string vpIoTools::getName(const std::string &pathname)
1218 {
1219  if (pathname.size() > 0) {
1220  std::string convertedPathname = vpIoTools::path(pathname);
1221 
1222  size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1223  if (index != std::string::npos) {
1224  return convertedPathname.substr(index + 1);
1225  }
1226 
1227  return convertedPathname;
1228  }
1229 
1230  return "";
1231 }
1232 
1239 std::string vpIoTools::getNameWE(const std::string &pathname)
1240 {
1241  std::string name = vpIoTools::getName(pathname);
1242  size_t found = name.find_last_of(".");
1243  std::string name_we = name.substr(0, found);
1244  return name_we;
1245 }
1246 
1284 long vpIoTools::getIndex(const std::string &filename, const std::string &format)
1285 {
1286  size_t indexBegin = format.find_last_of('%');
1287  size_t indexEnd = format.find_first_of('d', indexBegin);
1288  size_t suffixLength = format.length() - indexEnd - 1;
1289  // Extracting index
1290  if (filename.length() <= (suffixLength + indexBegin)) {
1291  return -1;
1292  }
1293  size_t indexLength = filename.length() - suffixLength - indexBegin;
1294  std::string indexSubstr = filename.substr(indexBegin, indexLength);
1295  std::istringstream ss(indexSubstr);
1296  long index = 0;
1297  ss >> index;
1298  if (ss.fail() || (index < 0) || (!ss.eof())) {
1299  return -1;
1300  }
1301 
1302  // Checking that format with inserted index equals filename
1303  char nameByFormat[FILENAME_MAX];
1304  snprintf(nameByFormat, FILENAME_MAX, format.c_str(), index);
1305  if (std::string(nameByFormat) != filename) {
1306  return -1;
1307  }
1308  return index;
1309 }
1310 
1326 std::string vpIoTools::getParent(const std::string &pathname)
1327 {
1328  if (pathname.size() > 0) {
1329  std::string convertedPathname = vpIoTools::path(pathname);
1330 
1331  size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1332  if (index != std::string::npos) {
1333  return convertedPathname.substr(0, index);
1334  }
1335 
1336  return ".";
1337  }
1338  else {
1339  return "";
1340  }
1341 }
1342 
1351 std::string vpIoTools::toLowerCase(const std::string &input)
1352 {
1353  std::string out;
1354 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1355  const std::string::const_iterator it_end = input.cend();
1356  for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) {
1357 #else
1358  const std::string::const_iterator it_end = input.end();
1359  for (std::string::const_iterator it = input.begin(); it != it_end; ++it) {
1360 #endif
1361  out += std::tolower(*it);
1362  }
1363  return out;
1364 }
1365 
1374 std::string vpIoTools::toUpperCase(const std::string &input)
1375 {
1376  std::string out;
1377 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1378  const std::string::const_iterator it_end = input.cend();
1379  for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) {
1380 #else
1381  const std::string::const_iterator it_end = input.end();
1382  for (std::string::const_iterator it = input.begin(); it != it_end; ++it) {
1383 #endif
1384  out += std::toupper(*it);
1385  }
1386  return out;
1387 }
1388 
1397 std::string vpIoTools::getAbsolutePathname(const std::string &pathname)
1398 {
1399 
1400 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1401  std::string real_path_str = pathname;
1402  char *real_path = realpath(pathname.c_str(), nullptr);
1403 
1404  if (real_path) {
1405  real_path_str = real_path;
1406  free(real_path);
1407  }
1408  return real_path_str;
1409 #elif defined(_WIN32)
1410 #if (!defined(WINRT))
1411  std::string real_path_str = pathname;
1412  DWORD retval = 0;
1413  TCHAR buffer[4096] = TEXT("");
1414 
1415  retval = GetFullPathName(pathname.c_str(), 4096, buffer, 0);
1416  if (retval != 0) {
1417  real_path_str = buffer;
1418  }
1419  return real_path_str;
1420 #else
1422  "Cannot get absolute path of %s: not implemented on "
1423  "Universal Windows Platform",
1424  pathname.c_str()));
1425 #endif
1426 #endif
1427 }
1428 
1439 std::string vpIoTools::createFilePath(const std::string &parent, const std::string &child)
1440 {
1441  if ((child.size() == 0) && (parent.size() == 0)) {
1442  return "";
1443  }
1444 
1445  if (child.size() == 0) {
1446  return vpIoTools::path(parent);
1447  }
1448 
1449  if (parent.size() == 0) {
1450  return vpIoTools::path(child);
1451  }
1452 
1453  std::string convertedParent = vpIoTools::path(parent);
1454  std::string convertedChild = vpIoTools::path(child);
1455 
1456  std::stringstream ss;
1457  ss << vpIoTools::separator;
1458  std::string stringSeparator;
1459  ss >> stringSeparator;
1460 
1461  std::string lastConvertedParentChar = convertedParent.substr(convertedParent.size() - 1);
1462  std::string firstConvertedChildChar = convertedChild.substr(0, 1);
1463 
1464  if (lastConvertedParentChar == stringSeparator) {
1465  convertedParent = convertedParent.substr(0, convertedParent.size() - 1);
1466  }
1467 
1468  if (firstConvertedChildChar == stringSeparator) {
1469  convertedChild = convertedChild.substr(1);
1470  }
1471 
1472  return std::string(convertedParent + vpIoTools::separator + convertedChild);
1473 }
1474 
1480 bool vpIoTools::isAbsolutePathname(const std::string &pathname)
1481 {
1482  // # Inspired by the Python 2.7.8 module.
1483  // # Return whether a path is absolute.
1484  // # Trivial in Posix, harder on the Mac or MS-DOS.
1485  // # For DOS it is absolute if it starts with a slash or backslash (current
1486  // # volume), or if a pathname after the volume letter and colon / UNC
1487  // resource # starts with a slash or backslash.
1488  //
1489  // def isabs(s):
1490  // """Test whether a path is absolute"""
1491  // s = splitdrive(s)[1]
1492  // return s != '' and s[:1] in '/\\'
1493  std::string path = splitDrive(pathname).second;
1494  return (path.size() > 0) && ((path.substr(0, 1) == "/") || (path.substr(0, 1) == "\\"));
1495 }
1496 
1504 bool vpIoTools::isSamePathname(const std::string &pathname1, const std::string &pathname2)
1505 {
1506  // Normalize path
1507  std::string path1_normalize = vpIoTools::path(pathname1);
1508  std::string path2_normalize = vpIoTools::path(pathname2);
1509 
1510  // Get absolute path
1511  path1_normalize = vpIoTools::getAbsolutePathname(path1_normalize);
1512  path2_normalize = vpIoTools::getAbsolutePathname(path2_normalize);
1513 
1514  return (path1_normalize == path2_normalize);
1515 }
1516 
1524 std::pair<std::string, std::string> vpIoTools::splitDrive(const std::string &pathname)
1525 {
1526  // # Split a path in a drive specification (a drive letter followed by a
1527  // # colon) and the path specification.
1528  // # It is always true that drivespec + pathspec == p
1529  // def splitdrive(p):
1530  // """Split a pathname into drive/UNC sharepoint and relative path
1531  // specifiers. Returns a 2-tuple (drive_or_unc, path); either part may be
1532  // empty.
1533  //
1534  // If you assign
1535  // result = splitdrive(p)
1536  // It is always true that:
1537  // result[0] + result[1] == p
1538  //
1539  // If the path contained a drive letter, drive_or_unc will contain
1540  // everything up to and including the colon. e.g. splitdrive("c:/dir")
1541  // returns ("c:", "/dir")
1542  //
1543  // If the path contained a UNC path, the drive_or_unc will contain the host
1544  // name and share up to but not including the fourth directory separator
1545  // character. e.g. splitdrive("//host/computer/dir") returns
1546  // ("//host/computer", "/dir")
1547  //
1548  // Paths cannot contain both a drive letter and a UNC path.
1549  //
1550  // """
1551  // if len(p) > 1:
1552  // normp = p.replace(altsep, sep)
1553  // if (normp[0:2] == sep*2) and (normp[2] != sep):
1554  // # is a UNC path:
1555  // # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1556  // # \\machine\mountpoint\directory\etc\...
1557  // # directory ^^^^^^^^^^^^^^^
1558  // index = normp.find(sep, 2)
1559  // if index == -1:
1560  // return '', p
1561  // index2 = normp.find(sep, index + 1)
1562  // # a UNC path can't have two slashes in a row
1563  // # (after the initial two)
1564  // if index2 == index + 1:
1565  // return '', p
1566  // if index2 == -1:
1567  // index2 = len(p)
1568  // return p[:index2], p[index2:]
1569  // if normp[1] == ':':
1570  // return p[:2], p[2:]
1571  // return '', p
1572 
1573  // On Unix, the drive is always empty.
1574  // On the Mac, the drive is always empty (don't use the volume name -- it
1575  // doesn't have the same syntactic and semantic oddities as DOS drive
1576  // letters, such as there being a separate current directory per drive).
1577 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1578  return std::pair<std::string, std::string>("", pathname);
1579 #else
1580  const std::string sep = "\\";
1581  const std::string sepsep = "\\\\";
1582  const std::string altsep = "/";
1583 
1584  if (pathname.size() > 1) {
1585  std::string normPathname = pathname;
1586  std::replace(normPathname.begin(), normPathname.end(), *altsep.c_str(), *sep.c_str());
1587 
1588  if (normPathname.substr(0, 2) == sepsep && normPathname.substr(2, 1) != sep) {
1589  // is a UNC path:
1590  // vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1591  // \\machine\mountpoint\directory\etc\...
1592  // directory ^^^^^^^^^^^^^^^
1593  size_t index = normPathname.find(sep, 2);
1594  if (index == std::string::npos) {
1595  return std::pair<std::string, std::string>("", pathname);
1596  }
1597 
1598  size_t index2 = normPathname.find(sep, index + 1);
1599  // # a UNC path can't have two slashes in a row
1600  // # (after the initial two)
1601  if (index2 == index + 1) {
1602  return std::pair<std::string, std::string>("", pathname);
1603  }
1604 
1605  if (index2 == std::string::npos) {
1606  index2 = pathname.size();
1607  }
1608 
1609  return std::pair<std::string, std::string>(pathname.substr(0, index2), pathname.substr(index2));
1610  }
1611 
1612  if (normPathname[1] == ':') {
1613  return std::pair<std::string, std::string>(pathname.substr(0, 2), pathname.substr(2));
1614  }
1615  }
1616 
1617  return std::pair<std::string, std::string>("", pathname);
1618 #endif
1619 }
1620 
1673 std::vector<std::string> vpIoTools::splitChain(const std::string &chain, const std::string &sep)
1674 {
1675  size_t startIndex = 0;
1676 
1677  std::string chainToSplit = chain;
1678  std::vector<std::string> subChain;
1679  size_t sepIndex = chainToSplit.find(sep);
1680 
1681  while (sepIndex != std::string::npos) {
1682  std::string sub = chainToSplit.substr(startIndex, sepIndex);
1683  if (!sub.empty()) {
1684  subChain.push_back(sub);
1685  }
1686  chainToSplit = chainToSplit.substr(sepIndex + 1, chain.size() - 1);
1687 
1688  sepIndex = chainToSplit.find(sep);
1689  }
1690  if (!chainToSplit.empty()) {
1691  subChain.push_back(chainToSplit);
1692  }
1693 
1694  return subChain;
1695 }
1696 
1704 std::vector<std::string> vpIoTools::getDirFiles(const std::string &pathname)
1705 {
1706 
1707  if (!checkDirectory(pathname)) {
1708  throw(vpIoException(vpException::fatalError, "Directory %s doesn't exist'", pathname.c_str()));
1709  }
1710  std::string dirName = path(pathname);
1711 
1712 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1713 
1714  std::vector<std::string> files;
1715  struct dirent **list = nullptr;
1716  int filesCount = scandir(dirName.c_str(), &list, nullptr, nullptr);
1717  if (filesCount == -1) {
1718  throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1719  }
1720  for (int i = 0; i < filesCount; ++i) {
1721  std::string fileName = list[i]->d_name;
1722  if ((fileName != ".") && (fileName != "..")) {
1723  files.push_back(fileName);
1724  }
1725  free(list[i]);
1726  }
1727  free(list);
1728  std::sort(files.begin(), files.end());
1729  return files;
1730 
1731 #elif defined(_WIN32)
1732 #if (!defined(WINRT))
1733 
1734  std::vector<std::string> files;
1735  std::string fileMask = dirName;
1736  fileMask.append("\\*");
1737  WIN32_FIND_DATA FindFileData;
1738  HANDLE hFind = FindFirstFile(fileMask.c_str(), &FindFileData);
1739  // Directory is empty
1740  if (HandleToLong(&hFind) == ERROR_FILE_NOT_FOUND) {
1741  return files;
1742  }
1743  if (hFind == INVALID_HANDLE_VALUE) {
1744  throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1745  }
1746  do {
1747  std::string fileName = FindFileData.cFileName;
1748  if (fileName != "." && fileName != "..") {
1749  files.push_back(fileName);
1750  }
1751  } while (FindNextFile(hFind, &FindFileData));
1752  FindClose(hFind);
1753  std::sort(files.begin(), files.end());
1754  return files;
1755 
1756 #else
1758  "Cannot read files of directory %s: not implemented on "
1759  "Universal Windows Platform",
1760  dirName.c_str()));
1761 #endif
1762 #endif
1763 }
1764 
1765 END_VISP_NAMESPACE
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ notImplementedError
Not implemented.
Definition: vpException.h:69
@ fatalError
Fatal error.
Definition: vpException.h:72
Error that can be emitted by the vpIoTools class and its derivatives.
Definition: vpIoException.h:55
@ invalidDirectoryName
Directory name is invalid.
Definition: vpIoException.h:63
@ cantCreateDirectory
Unable to create a directory.
Definition: vpIoException.h:64
@ cantGetenv
Cannot get environment variable value.
Definition: vpIoException.h:66
static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
Definition: vpIoTools.cpp:353
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1053
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
Definition: vpIoTools.cpp:1673
static std::string path(const std::string &pathname)
Definition: vpIoTools.cpp:1005
static std::string getAbsolutePathname(const std::string &pathname)
Definition: vpIoTools.cpp:1397
static std::string toLowerCase(const std::string &input)
Return a lower-case version of the string input . Numbers and special characters stay the same.
Definition: vpIoTools.cpp:1351
static bool checkFilename(const std::string &filename)
Definition: vpIoTools.cpp:786
static std::pair< std::string, std::string > splitDrive(const std::string &pathname)
Definition: vpIoTools.cpp:1524
static bool isSamePathname(const std::string &pathname1, const std::string &pathname2)
Definition: vpIoTools.cpp:1504
static std::string getTempPath()
Definition: vpIoTools.cpp:189
static bool isAbsolutePathname(const std::string &pathname)
Definition: vpIoTools.cpp:1480
static bool copy(const std::string &src, const std::string &dst)
Definition: vpIoTools.cpp:828
static bool checkDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:396
static bool rename(const std::string &oldfilename, const std::string &newfilename)
Definition: vpIoTools.cpp:985
static long getIndex(const std::string &filename, const std::string &format)
Definition: vpIoTools.cpp:1284
static std::string getUserName()
Definition: vpIoTools.cpp:285
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:1439
static std::string getenv(const std::string &env)
Definition: vpIoTools.cpp:326
static std::string getFileExtension(const std::string &pathname, bool checkFile=false)
Definition: vpIoTools.cpp:1136
static std::vector< std::string > getDirFiles(const std::string &dirname)
Definition: vpIoTools.cpp:1704
static void makeDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:550
static bool remove(const std::string &filename)
Definition: vpIoTools.cpp:921
static const std::string & getBuildInformation()
Definition: vpIoTools.cpp:126
static std::string getNameWE(const std::string &pathname)
Definition: vpIoTools.cpp:1239
static std::string makeTempDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:708
static bool checkFifo(const std::string &filename)
Definition: vpIoTools.cpp:456
static std::string getParent(const std::string &pathname)
Definition: vpIoTools.cpp:1326
static std::string getName(const std::string &pathname)
Definition: vpIoTools.cpp:1217
static std::string toUpperCase(const std::string &input)
Return a upper-case version of the string input . Numbers and special characters stay the same.
Definition: vpIoTools.cpp:1374
static const char separator
Definition: vpIoTools.h:532
static void makeFifo(const std::string &dirname)
Definition: vpIoTools.cpp:601