Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpIoTools.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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
38
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>// Mute warning with clang-cl
72// warning : non-portable path to file '<Windows.h>'; specified path differs in case from file name on disk [-Wnonportable-system-include-path]
73#if defined(__clang__)
74# pragma clang diagnostic push
75# pragma clang diagnostic ignored "-Wnonportable-system-include-path"
76#endif
77
78#include <windows.h>
79
80#if defined(__clang__)
81# pragma clang diagnostic pop
82#endif
83
84#endif
85#if !defined(_WIN32)
86#ifdef __ANDROID__
87// Like IOS, wordexp.cpp is not defined for Android
88#else
89#include <wordexp.h>
90#endif
91#endif
92
93#if defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin)
94#include <TargetConditionals.h> // To detect OSX or IOS using TARGET_OS_IOS macro
95#endif
96
97#ifndef PATH_MAX
98#ifdef _MAX_PATH
99#define PATH_MAX _MAX_PATH
100#else
101#define PATH_MAX 1024
102#endif
103#endif
104
105#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
106#define VP_STAT stat
107#elif defined(_WIN32) && defined(__MINGW32__)
108#define VP_STAT stat
109#elif defined(_WIN32)
110#define VP_STAT _stat
111#else
112#define VP_STAT stat
113#endif
114namespace
115{
116// The following code is not working on iOS since wordexp() is not available
117// The function is not used on Android
118#if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
119#if (TARGET_OS_IOS == 0) && !defined(__ANDROID__)
120void replaceAll(std::string &str, const std::string &search, const std::string &replace)
121{
122 size_t start_pos = 0;
123 while ((start_pos = str.find(search, start_pos)) != std::string::npos) {
124 str.replace(start_pos, search.length(), replace);
125 start_pos += replace.length(); // Handles case where 'replace' is a
126 // substring of 'search'
127 }
128}
129#endif
130#endif
131} // namespace
132
139{
140#ifdef ENABLE_BUILD_INFO
141 VP_ATTRIBUTE_NO_DESTROY static const std::string build_info =
142#include "version_string.inc"
143 ;
144 return build_info;
145#else
146 VP_ATTRIBUTE_NO_DESTROY static const std::string build_info = "Build info is not available";
147 return build_info;
148#endif
149}
150
207{
208#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
209 std::string username;
210 vpIoTools::getUserName(username);
211 return "/tmp/" + username;
212#elif defined(_WIN32) && !defined(WINRT)
213 // https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-using-a-temporary-file
214 // Gets the temp path env string (no guarantee it's a valid path).
215 TCHAR lpTempPathBuffer[MAX_PATH];
216 DWORD dwRetVal = GetTempPath(MAX_PATH /* length of the buffer */, lpTempPathBuffer /* buffer for path */);
217 if (dwRetVal > MAX_PATH || (dwRetVal == 0)) {
218 throw vpIoException(vpIoException::cantGetenv, "Error with GetTempPath() call!");
219 }
220 std::string temp_path(lpTempPathBuffer);
221 if (!temp_path.empty()) {
222 if (temp_path.back() == '\\') {
223 temp_path.resize(temp_path.size() - 1);
224 }
225 }
226 else {
227 temp_path = "C:\temp";
228 try {
229 vpIoTools::makeDirectory(temp_path);
230 }
231 catch (...) {
232 throw(vpException(vpException::fatalError, "Cannot set temp path to %s", temp_path.c_str()));
233 }
234 }
235 return temp_path;
236#else
237 throw vpIoException(vpException::fatalError, "Not implemented on this platform!");
238#endif
239}
240
254void vpIoTools::getUserName(std::string &username)
255{
256 // With MinGW, UNIX and _WIN32 are defined
257#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
258 // Get the user name.
259 char *logname = ::getenv("LOGNAME");
260 if (!logname) {
261 username = "unknown";
262 }
263 else {
264 username = logname;
265 }
266#elif defined(_WIN32)
267#if (!defined(WINRT))
268 unsigned int info_buffer_size = 1024;
269 TCHAR *infoBuf = new TCHAR[info_buffer_size];
270 DWORD bufCharCount = static_cast<DWORD>(info_buffer_size);
271 // Get the user name.
272 if (!GetUserName(infoBuf, &bufCharCount)) {
273 username = "unknown";
274 }
275 else {
276 username = infoBuf;
277 }
278 delete[] infoBuf;
279#else
280 // Universal platform
281 username = "unknown";
282#endif
283#else
284 username = "unknown";
285#endif
286}
287
303{
304 std::string username;
305 getUserName(username);
306 return username;
307}
308
343std::string vpIoTools::getenv(const std::string &env)
344{
345#if defined(_WIN32) && defined(WINRT)
346 throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value: not "
347 "implemented on Universal Windows Platform"));
348#else
349 std::string value;
350 // Get the environment variable value.
351 char *v_value = ::getenv(env.c_str());
352 if (!v_value) {
353 throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value"));
354 }
355 value = v_value;
356
357 return value;
358#endif
359}
360
370void vpIoTools::getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
371{
372 if (version.size() == 0) {
373 major = 0;
374 minor = 0;
375 patch = 0;
376 }
377 else {
378 size_t major_pos = version.find('.');
379 std::string major_str = version.substr(0, major_pos);
380 major = static_cast<unsigned>(atoi(major_str.c_str()));
381
382 if (major_pos != std::string::npos) {
383 size_t minor_pos = version.find('.', major_pos + 1);
384 std::string minor_str = version.substr(major_pos + 1, (minor_pos - (major_pos + 1)));
385 minor = static_cast<unsigned>(atoi(minor_str.c_str()));
386
387 if (minor_pos != std::string::npos) {
388 std::string patch_str = version.substr(minor_pos + 1);
389 patch = static_cast<unsigned>(atoi(patch_str.c_str()));
390 }
391 else {
392 patch = 0;
393 }
394 }
395 else {
396 minor = 0;
397 patch = 0;
398 }
399 }
400}
401
413bool vpIoTools::checkDirectory(const std::string &dirname)
414{
415#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
416 struct stat stbuf;
417#elif defined(_WIN32) && defined(__MINGW32__)
418 struct stat stbuf;
419#elif defined(_WIN32)
420 struct _stat stbuf;
421#endif
422
423 if (dirname.empty()) {
424 return false;
425 }
426
427 std::string path_dirname = path(dirname);
428
429 if (VP_STAT(path_dirname.c_str(), &stbuf) != 0) {
430 // Test adding the separator if not already present
431 if (path_dirname.at(path_dirname.size() - 1) != separator) {
432 if (VP_STAT((path_dirname + separator).c_str(), &stbuf) != 0) {
433 return false;
434 }
435 }
436 // Test removing the separator if already present
437 if (path_dirname.at(path_dirname.size() - 1) == separator) {
438 if (VP_STAT((path_dirname.substr(0, path_dirname.size() - 1)).c_str(), &stbuf) != 0) {
439 return false;
440 }
441 }
442 }
443
444#if defined(_WIN32) || (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
445 if ((stbuf.st_mode & S_IFDIR) == 0)
446#endif
447 {
448 return false;
449 }
450#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
451 if ((stbuf.st_mode & S_IWUSR) == 0)
452#elif defined(_WIN32)
453 if ((stbuf.st_mode & S_IWRITE) == 0)
454#endif
455 {
456 return false;
457 }
458 return true;
459}
460
473bool vpIoTools::checkFifo(const std::string &fifofilename)
474{
475#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
476 struct stat stbuf;
477
478 std::string v_filename = path(fifofilename);
479 if (stat(v_filename.c_str(), &stbuf) != 0) {
480 return false;
481 }
482 if ((stbuf.st_mode & S_IFIFO) == 0) {
483 return false;
484 }
485 if ((stbuf.st_mode & S_IRUSR) == 0)
486
487 {
488 return false;
489 }
490 return true;
491#elif defined(_WIN32)
492 (void)fifofilename;
493 throw(vpIoException(vpIoException::notImplementedError, "Fifo files are not supported on Windows platforms."));
494#endif
495}
496
497#ifndef DOXYGEN_SHOULD_SKIP_THIS
498int vpIoTools::mkdir_p(const std::string &path, int mode)
499{
500 errno = 0;
501 if (path.size() > PATH_MAX) {
502 errno = ENAMETOOLONG;
503 return -1;
504 }
505
506 // Iterate over the string
507 std::string cpy_path = path;
508 std::string sub_path;
509 size_t pos = 0;
510 while (pos != std::string::npos) {
511 sub_path += cpy_path.substr(0, pos + 1);
512 // Continue if sub_path = separator
513 bool stop_for_loop = false;
514 if (pos == 0) {
515 cpy_path.erase(0, pos + 1);
516 stop_for_loop = true;
517 }
518 if (!stop_for_loop) {
519#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
520 if (mkdir(sub_path.c_str(), static_cast<mode_t>(mode)) != 0)
521#elif defined(_WIN32)
522 (void)mode; // var not used
523 if (!checkDirectory(sub_path) && _mkdir(sub_path.c_str()) != 0)
524#endif
525 {
526 if (errno != EEXIST) {
527 return -1;
528 }
529 }
530 cpy_path.erase(0, pos + 1);
531 }
532 pos = cpy_path.find(vpIoTools::separator);
533 }
534
535 if (!cpy_path.empty()) {
536 sub_path += cpy_path;
537#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
538 if (mkdir(sub_path.c_str(), static_cast<mode_t>(mode)) != 0)
539#elif defined(_WIN32)
540
541 if (_mkdir(sub_path.c_str()) != 0)
542#endif
543 {
544 if (errno != EEXIST) {
545 return -1;
546 }
547 }
548 }
549
550 return 0;
551}
552
553#endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
554
567void vpIoTools::makeDirectory(const std::string &dirname)
568{
569#if ((!defined(__unix__) && !defined(__unix) && (!defined(__APPLE__) || !defined(__MACH__)))) && !defined(_WIN32)
570 std::cerr << "Unsupported platform for vpIoTools::makeDirectory()!" << std::endl;
571 return;
572#endif
573
574#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
575 struct stat stbuf;
576#elif defined(_WIN32) && defined(__MINGW32__)
577 struct stat stbuf;
578#elif defined(_WIN32)
579 struct _stat stbuf;
580#endif
581
582 if (dirname.empty()) {
583 throw(vpIoException(vpIoException::invalidDirectoryName, "invalid directory name"));
584 }
585
586 std::string v_dirname = path(dirname);
587
588#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
589 if (stat(v_dirname.c_str(), &stbuf) != 0)
590#elif defined(_WIN32) && defined(__MINGW32__)
591 if (stat(v_dirname.c_str(), &stbuf) != 0)
592#elif defined(_WIN32)
593 if (_stat(v_dirname.c_str(), &stbuf) != 0)
594#endif
595 {
596 if (vpIoTools::mkdir_p(v_dirname, 0755) != 0) {
597 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str()));
598 }
599 }
600
601 if (checkDirectory(dirname) == false) {
602 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str()));
603 }
604}
605
618void vpIoTools::makeFifo(const std::string &fifoname)
619{
620#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
621
622 // If dirname is a directory, we throw an error
623 if (vpIoTools::checkDirectory(fifoname)) {
625 "Unable to create fifo file. '%s' is an existing directory.", fifoname.c_str()));
626 }
627
628 // If dirname refers to an already existing file, we throw an error
629 else if (vpIoTools::checkFilename(fifoname)) {
630 throw(vpIoException(vpIoException::invalidDirectoryName, "Unable to create fifo file '%s'. File already exists.",
631 fifoname.c_str()));
632 // If dirname refers to an already existing fifo, we throw an error
633 }
634 else if (vpIoTools::checkFifo(fifoname)) {
635 throw(vpIoException(vpIoException::invalidDirectoryName, "Unable to create fifo file '%s'. Fifo already exists.",
636 fifoname.c_str()));
637 }
638
639 else if (mkfifo(fifoname.c_str(), 0666) < 0) {
640 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create fifo file '%s'.", fifoname.c_str()));
641 }
642#elif defined(_WIN32)
643 (void)fifoname;
644 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create fifo on Windows platforms."));
645#endif
646}
647
648#if defined(_WIN32) && !defined(WINRT)
649std::string getUuid();
650
651std::string getUuid()
652{
653 UUID uuid;
654 if (UuidCreate(&uuid) != RPC_S_OK) {
655 throw(vpIoException(vpIoException::fatalError, "UuidCreate() failed!"));
656 }
657
658 RPC_CSTR stringUuid;
659 if (UuidToString(&uuid, &stringUuid) != RPC_S_OK) {
660 throw(vpIoException(vpIoException::fatalError, "UuidToString() failed!"));
661 }
662
663 return reinterpret_cast<char *>(stringUuid);
664}
665#endif
666
727std::string vpIoTools::makeTempDirectory(const std::string &dirname)
728{
729#if defined(WINRT) || !defined(_WIN32) && !(defined(__unix__) || defined(__unix) || \
730 (defined(__APPLE__) && defined(__MACH__))) // not UNIX and not Windows
731 throw(vpIoException(vpIoException::cantCreateDirectory, "makeTempDirectory() is not supported on this platform!"));
732#endif
733
734 std::string dirname_cpy = std::string(dirname);
735 std::string correctEnding = "XXXXXX";
736
737 // If dirname is an unexisting directory, it should end with XXXXXX in order to create a temp directory
738 if (!vpIoTools::checkDirectory(dirname_cpy)) {
739#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
740 // Check if dirname ends with XXXXXX
741 if (dirname_cpy.rfind(correctEnding) == std::string::npos) {
742 if (dirname_cpy.at(dirname_cpy.length() - 1) != '/') {
743 dirname_cpy = dirname_cpy + "/";
744 }
745 try {
746 vpIoTools::makeDirectory(dirname_cpy);
747 }
748 catch (...) {
749 throw(vpException(vpException::fatalError, "Cannot create temp directory %s", dirname_cpy.c_str()));
750 }
751
752 dirname_cpy = dirname_cpy + "XXXXXX";
753 }
754
755#elif defined(_WIN32) && !defined(WINRT)
756 // Remove XXXXXX
757 dirname_cpy = dirname_cpy.substr(0, dirname_cpy.rfind(correctEnding));
758 // Append UUID
759 dirname_cpy = dirname_cpy + getUuid();
760#endif
761
762 }
763 else {
764 // If dirname is an existing directory, we create a temp directory inside
765#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
766 if (dirname_cpy.at(dirname_cpy.length() - 1) != '/') {
767 dirname_cpy = dirname_cpy + "/";
768 }
769 dirname_cpy = dirname_cpy + "XXXXXX";
770#elif defined(_WIN32) && !defined(WINRT)
771 dirname_cpy = createFilePath(dirname_cpy, getUuid());
772#endif
773 }
774
775#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
776 char *dirname_char = new char[dirname_cpy.length() + 1];
777 strcpy(dirname_char, dirname_cpy.c_str());
778
779 char *computedDirname = mkdtemp(dirname_char);
780
781 if (!computedDirname) {
782 delete[] dirname_char;
783 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'.", dirname_cpy.c_str()));
784 }
785
786 std::string res(computedDirname);
787 delete[] dirname_char;
788 return res;
789#elif defined(_WIN32) && !defined(WINRT)
790 makeDirectory(dirname_cpy);
791 return dirname_cpy;
792#endif
793}
794
805bool vpIoTools::checkFilename(const std::string &filename)
806{
807#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
808 struct stat stbuf;
809#elif defined(_WIN32)
810 struct _stat stbuf;
811#endif
812
813 if (filename.empty()) {
814 return false;
815 }
816
817 std::string v_filename = path(filename);
818#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
819 if (stat(v_filename.c_str(), &stbuf) != 0)
820#elif defined(_WIN32)
821 if (_stat(v_filename.c_str(), &stbuf) != 0)
822#endif
823 {
824 return false;
825 }
826 if ((stbuf.st_mode & S_IFREG) == 0) {
827 return false;
828 }
829#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
830 if ((stbuf.st_mode & S_IRUSR) == 0)
831#elif defined(_WIN32)
832 if ((stbuf.st_mode & S_IREAD) == 0)
833#endif
834 {
835 return false;
836 }
837 return true;
838}
839
847bool vpIoTools::copy(const std::string &src, const std::string &dst)
848{
849 // Check if we have to consider a file or a directory
850 if (vpIoTools::checkFilename(src)) {
851 // --comment: std::cout "copy file: " src " in " dst std::endl;
852#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
853#if TARGET_OS_IOS == 0 // The following code is not working on iOS since
854 // wordexp() is not available
855 std::stringstream cmd;
856 cmd << "cp -p ";
857 cmd << src;
858 cmd << " ";
859 cmd << dst;
860 int ret = system(cmd.str().c_str());
861 if (ret) {
862 } // to avoid a warning
863 // std::cout << cmd << " return value: " << ret << std::endl;
864 return true;
865#else
866 throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src.c_str(),
867 dst.c_str()));
868#endif
869#elif defined(_WIN32)
870#if (!defined(WINRT))
871 std::stringstream cmd;
872 cmd << "copy ";
873 cmd << vpIoTools::path(src);
874 cmd << " ";
875 cmd << vpIoTools::path(dst);
876 int ret = system(cmd.str().c_str());
877 if (ret) {
878 } // to avoid a warning
879 // std::cout << cmd << " return value: " << ret << std::endl;
880 return true;
881#else
882 throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
883 src.c_str(), dst.c_str()));
884#endif
885#endif
886 }
887 else if (vpIoTools::checkDirectory(src)) {
888 // --comment: std::cout "copy directory: " src " in " dst
889#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
890#if TARGET_OS_IOS == 0 // The following code is not working on iOS since
891 // wordexp() is not available
892 std::stringstream cmd;
893 cmd << "cp -p ";
894 cmd << src;
895 cmd << " ";
896 cmd << dst;
897 int ret = system(cmd.str().c_str());
898 if (ret) {
899 } // to avoid a warning
900 // std::cout << cmd << " return value: " << ret << std::endl;
901 return true;
902#else
903 throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src.c_str(),
904 dst.c_str()));
905#endif
906#elif defined(_WIN32)
907#if (!defined(WINRT))
908 std::stringstream cmd;
909 cmd << "copy ";
910 cmd << vpIoTools::path(src);
911 cmd << " ";
912 cmd << vpIoTools::path(dst);
913 int ret = system(cmd.str().c_str());
914 if (ret) {
915 } // to avoid a warning
916 // std::cout << cmd << " return value: " << ret << std::endl;
917 return true;
918#else
919 throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
920 src.c_str(), dst.c_str()));
921#endif
922#endif
923 }
924 else {
925 std::cout << "Cannot copy: " << src << " in " << dst << std::endl;
926 return false;
927 }
928}
929
940bool vpIoTools::remove(const std::string &file_or_dir)
941{
942 // Check if we have to consider a file or a directory
943 if (vpIoTools::checkFilename(file_or_dir)
944#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
945 || vpIoTools::checkFifo(std::string(file_or_dir))
946#endif
947 ) {
948 if (::remove(file_or_dir.c_str()) != 0) {
949 return false;
950 }
951 else {
952 return true;
953 }
954 }
955 else if (vpIoTools::checkDirectory(file_or_dir)) {
956#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
957#if TARGET_OS_IOS == 0 // The following code is not working on iOS since
958 // wordexp() is not available
959 std::stringstream cmd;
960 cmd << "rm -rf \"";
961 cmd << file_or_dir;
962 cmd << "\"";
963 int ret = system(cmd.str().c_str());
964 if (ret) {
965 } // to avoid a warning
966 // std::cout << cmd << " return value: " << ret << std::endl;
967 return true;
968#else
969 throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on iOS Platform",
970 file_or_dir.c_str()));
971#endif
972#elif defined(_WIN32)
973#if (!defined(WINRT))
974 std::stringstream cmd;
975 cmd << "rmdir /S /Q ";
976 cmd << vpIoTools::path(file_or_dir);
977 cmd << "\"";
978 int ret = system(cmd.str().c_str());
979 if (ret) {
980 } // to avoid a warning
981 // std::cout << cmd << " return value: " << ret << std::endl;
982 return true;
983#else
984 throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on Universal Windows Platform",
985 file_or_dir.c_str()));
986#endif
987#endif
988 }
989 else {
990 std::cout << "Cannot remove: " << file_or_dir << std::endl;
991 return false;
992 }
993}
994
1004bool vpIoTools::rename(const std::string &oldfilename, const std::string &newfilename)
1005{
1006 if (::rename(oldfilename.c_str(), newfilename.c_str()) != 0) {
1007 return false;
1008 }
1009 else {
1010 return true;
1011 }
1012}
1013
1024std::string vpIoTools::path(const std::string &pathname)
1025{
1026 std::string path(pathname);
1027
1028#if defined(_WIN32)
1029 for (unsigned int i = 0; i < path.length(); ++i)
1030 if (path[i] == '/')
1031 path[i] = '\\';
1032#elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
1033 unsigned int path_length = path.length();
1034 for (unsigned int i = 0; i < path_length; ++i) {
1035 if (path[i] == '\\') {
1036 path[i] = '/';
1037 }
1038 }
1039#if TARGET_OS_IOS == 0 // The following code is not working on iOS and android since
1040 // wordexp() is not available
1041#ifdef __ANDROID__
1042// Do nothing
1043#else
1044 wordexp_t exp_result;
1045
1046 // escape quote character
1047 replaceAll(path, "'", "'\\''");
1048 // add quotes to handle special characters like parentheses and spaces
1049 wordexp(std::string("'" + path + "'").c_str(), &exp_result, 0);
1050 path = exp_result.we_wordc == 1 ? exp_result.we_wordv[0] : "";
1051 wordfree(&exp_result);
1052#endif
1053#endif
1054#endif
1055
1056 return path;
1057}
1058
1073{
1074 std::string data_path;
1075 std::string file_to_test("mbt/cube.cao");
1076 std::string filename;
1077 // Test if VISP_INPUT_IMAGE_PATH env var is set
1078 try {
1079 data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH");
1080 filename = data_path + "/" + file_to_test;
1081 if (vpIoTools::checkFilename(filename)) {
1082 return data_path;
1083 }
1084 }
1085 catch (...) {
1086 }
1087 try {
1088 data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/ViSP-images";
1089 filename = data_path + "/" + file_to_test;
1090 if (vpIoTools::checkFilename(filename)) {
1091 return data_path;
1092 }
1093 }
1094 catch (...) {
1095 }
1096 try {
1097 data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/visp-images";
1098 filename = data_path + "/" + file_to_test;
1099 if (vpIoTools::checkFilename(filename)) {
1100 return data_path;
1101 }
1102 }
1103 catch (...) {
1104 }
1105
1106#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1107 // Test if visp-images-data package is installed (Ubuntu and Debian)
1108 data_path = "/usr/share/visp-images-data/ViSP-images";
1109 filename = data_path + "/" + file_to_test;
1110 if (vpIoTools::checkFilename(filename)) {
1111 return data_path;
1112 }
1113 data_path = "/usr/share/visp-images-data/visp-images";
1114 filename = data_path + "/" + file_to_test;
1115 if (vpIoTools::checkFilename(filename)) {
1116 return data_path;
1117 }
1118#endif
1119 data_path = "";
1120 return data_path;
1121}
1122
1155std::string vpIoTools::getFileExtension(const std::string &pathname, bool checkFile)
1156{
1157 if (checkFile && (vpIoTools::checkDirectory(pathname) || (!vpIoTools::checkFilename(pathname)))) {
1158 return "";
1159 }
1160
1161#if defined(_WIN32)
1162 std::string sep = "\\";
1163 std::string altsep = "/";
1164 std::string extsep = ".";
1165#else
1166 // On Unix, or on the Mac
1167 std::string sep = "/";
1168 std::string altsep = "";
1169 std::string extsep = ".";
1170#endif
1171
1172 // Python 2.7.8 module.
1173 // # Split a path in root and extension.
1174 // # The extension is everything starting at the last dot in the last
1175 // # pathname component; the root is everything before that.
1176 // # It is always true that root + ext == p.
1177 //
1178 // # Generic implementation of splitext, to be parametrized with
1179 // # the separators
1180 // def _splitext(p, sep, altsep, extsep):
1181 // """Split the extension from a pathname.
1182 //
1183 // Extension is everything from the last dot to the end, ignoring
1184 // leading dots. Returns "(root, ext)"; ext may be empty."""
1185 //
1186 // sepIndex = p.rfind(sep)
1187 // if altsep:
1188 // altsepIndex = p.rfind(altsep)
1189 // sepIndex = max(sepIndex, altsepIndex)
1190 //
1191 // dotIndex = p.rfind(extsep)
1192 // if dotIndex > sepIndex:
1193 // # skip all leading dots
1194 // filenameIndex = sepIndex + 1
1195 // while filenameIndex < dotIndex:
1196 // if p[filenameIndex] != extsep:
1197 // return p[:dotIndex], p[dotIndex:]
1198 // filenameIndex += 1
1199 //
1200 // return p, ''
1201
1202 int sepIndex = static_cast<int>(pathname.rfind(sep));
1203 if (!altsep.empty()) {
1204 int altsepIndex = static_cast<int>(pathname.rfind(altsep));
1205 sepIndex = std::max<int>(sepIndex, altsepIndex);
1206 }
1207
1208 size_t dotIndex = pathname.rfind(extsep);
1209 if (dotIndex != std::string::npos) {
1210 // The extsep character exists
1211 size_t npos = std::string::npos;
1212 if (((sepIndex != static_cast<int>(npos)) && (static_cast<int>(dotIndex) > sepIndex)) ||
1213 (sepIndex == static_cast<int>(npos))) {
1214 if (sepIndex == static_cast<int>(npos)) {
1215 sepIndex = 0;
1216 }
1217 size_t filenameIndex = static_cast<size_t>(sepIndex) + static_cast<size_t>(1);
1218
1219 while (filenameIndex < dotIndex) {
1220 if (pathname.compare(filenameIndex, 1, extsep) != 0) {
1221 return pathname.substr(dotIndex);
1222 }
1223 filenameIndex++;
1224 }
1225 }
1226 }
1227
1228 return "";
1229}
1230
1236std::string vpIoTools::getName(const std::string &pathname)
1237{
1238 if (pathname.size() > 0) {
1239 std::string convertedPathname = vpIoTools::path(pathname);
1240
1241 size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1242 if (index != std::string::npos) {
1243 return convertedPathname.substr(index + 1);
1244 }
1245
1246 return convertedPathname;
1247 }
1248
1249 return "";
1250}
1251
1258std::string vpIoTools::getNameWE(const std::string &pathname)
1259{
1260 std::string name = vpIoTools::getName(pathname);
1261 size_t found = name.find_last_of(".");
1262 std::string name_we = name.substr(0, found);
1263 return name_we;
1264}
1265
1303long vpIoTools::getIndex(const std::string &filename, const std::string &format)
1304{
1305 size_t indexBegin = format.find_last_of('%');
1306 size_t indexEnd = format.find_first_of('d', indexBegin);
1307 size_t suffixLength = format.length() - indexEnd - 1;
1308 // Extracting index
1309 if (filename.length() <= (suffixLength + indexBegin)) {
1310 return -1;
1311 }
1312 size_t indexLength = filename.length() - suffixLength - indexBegin;
1313 std::string indexSubstr = filename.substr(indexBegin, indexLength);
1314 std::istringstream ss(indexSubstr);
1315 long index = 0;
1316 ss >> index;
1317 if (ss.fail() || (index < 0) || (!ss.eof())) {
1318 return -1;
1319 }
1320
1321 // Checking that format with inserted index equals filename
1322 char nameByFormat[FILENAME_MAX];
1323 snprintf(nameByFormat, FILENAME_MAX, format.c_str(), index);
1324 if (std::string(nameByFormat) != filename) {
1325 return -1;
1326 }
1327 return index;
1328}
1329
1345std::string vpIoTools::getParent(const std::string &pathname)
1346{
1347 if (pathname.size() > 0) {
1348 std::string convertedPathname = vpIoTools::path(pathname);
1349
1350 size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1351 if (index != std::string::npos) {
1352 return convertedPathname.substr(0, index);
1353 }
1354
1355 return ".";
1356 }
1357 else {
1358 return "";
1359 }
1360}
1361
1370std::string vpIoTools::toLowerCase(const std::string &input)
1371{
1372 std::string out;
1373#if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1374 const std::string::const_iterator it_end = input.cend();
1375 for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) {
1376#else
1377 const std::string::const_iterator it_end = input.end();
1378 for (std::string::const_iterator it = input.begin(); it != it_end; ++it) {
1379#endif
1380 out += std::tolower(*it);
1381 }
1382 return out;
1383}
1384
1393std::string vpIoTools::toUpperCase(const std::string &input)
1394{
1395 std::string out;
1396#if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1397 const std::string::const_iterator it_end = input.cend();
1398 for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) {
1399#else
1400 const std::string::const_iterator it_end = input.end();
1401 for (std::string::const_iterator it = input.begin(); it != it_end; ++it) {
1402#endif
1403 out += std::toupper(*it);
1404 }
1405 return out;
1406}
1407
1442std::string vpIoTools::formatString(const std::string &name, unsigned int val)
1443{
1444 const char *fmt = name.c_str();
1445 int sz = std::snprintf(nullptr, 0, fmt, val);
1446 sz += 1; // note +1 for null terminator
1447 std::vector<char> buf(sz);
1448 std::snprintf(buf.data(), sz, fmt, val);
1449 std::string str(buf.begin(), buf.end());
1450#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1451 str.pop_back(); // Only since cxx11
1452#else
1453 str.erase(str.end()-1, str.end());
1454#endif
1455 return str;
1456}
1457
1466std::string vpIoTools::getAbsolutePathname(const std::string &pathname)
1467{
1468
1469#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1470 std::string real_path_str = pathname;
1471 char *real_path = realpath(pathname.c_str(), nullptr);
1472
1473 if (real_path) {
1474 real_path_str = real_path;
1475 free(real_path);
1476 }
1477 return real_path_str;
1478#elif defined(_WIN32)
1479#if (!defined(WINRT))
1480 std::string real_path_str = pathname;
1481 DWORD retval = 0;
1482 TCHAR buffer[4096] = TEXT("");
1483
1484 retval = GetFullPathName(pathname.c_str(), 4096, buffer, 0);
1485 if (retval != 0) {
1486 real_path_str = buffer;
1487 }
1488 return real_path_str;
1489#else
1491 "Cannot get absolute path of %s: not implemented on "
1492 "Universal Windows Platform",
1493 pathname.c_str()));
1494#endif
1495#endif
1496}
1497
1508std::string vpIoTools::createFilePath(const std::string &parent, const std::string &child)
1509{
1510 if ((child.size() == 0) && (parent.size() == 0)) {
1511 return "";
1512 }
1513
1514 if (child.size() == 0) {
1515 return vpIoTools::path(parent);
1516 }
1517
1518 if (parent.size() == 0) {
1519 return vpIoTools::path(child);
1520 }
1521
1522 std::string convertedParent = vpIoTools::path(parent);
1523 std::string convertedChild = vpIoTools::path(child);
1524
1525 std::stringstream ss;
1527 std::string stringSeparator;
1528 ss >> stringSeparator;
1529
1530 std::string lastConvertedParentChar = convertedParent.substr(convertedParent.size() - 1);
1531 std::string firstConvertedChildChar = convertedChild.substr(0, 1);
1532
1533 if (lastConvertedParentChar == stringSeparator) {
1534 convertedParent = convertedParent.substr(0, convertedParent.size() - 1);
1535 }
1536
1537 if (firstConvertedChildChar == stringSeparator) {
1538 convertedChild = convertedChild.substr(1);
1539 }
1540
1541 return std::string(convertedParent + vpIoTools::separator + convertedChild);
1542}
1543
1549bool vpIoTools::isAbsolutePathname(const std::string &pathname)
1550{
1551 // # Inspired by the Python 2.7.8 module.
1552 // # Return whether a path is absolute.
1553 // # Trivial in Posix, harder on the Mac or MS-DOS.
1554 // # For DOS it is absolute if it starts with a slash or backslash (current
1555 // # volume), or if a pathname after the volume letter and colon / UNC
1556 // resource # starts with a slash or backslash.
1557 //
1558 // def isabs(s):
1559 // """Test whether a path is absolute"""
1560 // s = splitdrive(s)[1]
1561 // return s != '' and s[:1] in '/\\'
1562 std::string path = splitDrive(pathname).second;
1563 return (path.size() > 0) && ((path.substr(0, 1) == "/") || (path.substr(0, 1) == "\\"));
1564}
1565
1573bool vpIoTools::isSamePathname(const std::string &pathname1, const std::string &pathname2)
1574{
1575 // Normalize path
1576 std::string path1_normalize = vpIoTools::path(pathname1);
1577 std::string path2_normalize = vpIoTools::path(pathname2);
1578
1579 // Get absolute path
1580 path1_normalize = vpIoTools::getAbsolutePathname(path1_normalize);
1581 path2_normalize = vpIoTools::getAbsolutePathname(path2_normalize);
1582
1583 return (path1_normalize == path2_normalize);
1584}
1585
1593std::pair<std::string, std::string> vpIoTools::splitDrive(const std::string &pathname)
1594{
1595 // # Split a path in a drive specification (a drive letter followed by a
1596 // # colon) and the path specification.
1597 // # It is always true that drivespec + pathspec == p
1598 // def splitdrive(p):
1599 // """Split a pathname into drive/UNC sharepoint and relative path
1600 // specifiers. Returns a 2-tuple (drive_or_unc, path); either part may be
1601 // empty.
1602 //
1603 // If you assign
1604 // result = splitdrive(p)
1605 // It is always true that:
1606 // result[0] + result[1] == p
1607 //
1608 // If the path contained a drive letter, drive_or_unc will contain
1609 // everything up to and including the colon. e.g. splitdrive("c:/dir")
1610 // returns ("c:", "/dir")
1611 //
1612 // If the path contained a UNC path, the drive_or_unc will contain the host
1613 // name and share up to but not including the fourth directory separator
1614 // character. e.g. splitdrive("//host/computer/dir") returns
1615 // ("//host/computer", "/dir")
1616 //
1617 // Paths cannot contain both a drive letter and a UNC path.
1618 //
1619 // """
1620 // if len(p) > 1:
1621 // normp = p.replace(altsep, sep)
1622 // if (normp[0:2] == sep*2) and (normp[2] != sep):
1623 // # is a UNC path:
1624 // # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1625 // # \\machine\mountpoint\directory\etc\...
1626 // # directory ^^^^^^^^^^^^^^^
1627 // index = normp.find(sep, 2)
1628 // if index == -1:
1629 // return '', p
1630 // index2 = normp.find(sep, index + 1)
1631 // # a UNC path can't have two slashes in a row
1632 // # (after the initial two)
1633 // if index2 == index + 1:
1634 // return '', p
1635 // if index2 == -1:
1636 // index2 = len(p)
1637 // return p[:index2], p[index2:]
1638 // if normp[1] == ':':
1639 // return p[:2], p[2:]
1640 // return '', p
1641
1642 // On Unix, the drive is always empty.
1643 // On the Mac, the drive is always empty (don't use the volume name -- it
1644 // doesn't have the same syntactic and semantic oddities as DOS drive
1645 // letters, such as there being a separate current directory per drive).
1646#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1647 return std::pair<std::string, std::string>("", pathname);
1648#else
1649 const std::string sep = "\\";
1650 const std::string sepsep = "\\\\";
1651 const std::string altsep = "/";
1652
1653 if (pathname.size() > 1) {
1654 std::string normPathname = pathname;
1655 std::replace(normPathname.begin(), normPathname.end(), *altsep.c_str(), *sep.c_str());
1656
1657 if (normPathname.substr(0, 2) == sepsep && normPathname.substr(2, 1) != sep) {
1658 // is a UNC path:
1659 // vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1660 // \\machine\mountpoint\directory\etc\...
1661 // directory ^^^^^^^^^^^^^^^
1662 size_t index = normPathname.find(sep, 2);
1663 if (index == std::string::npos) {
1664 return std::pair<std::string, std::string>("", pathname);
1665 }
1666
1667 size_t index2 = normPathname.find(sep, index + 1);
1668 // # a UNC path can't have two slashes in a row
1669 // # (after the initial two)
1670 if (index2 == index + 1) {
1671 return std::pair<std::string, std::string>("", pathname);
1672 }
1673
1674 if (index2 == std::string::npos) {
1675 index2 = pathname.size();
1676 }
1677
1678 return std::pair<std::string, std::string>(pathname.substr(0, index2), pathname.substr(index2));
1679 }
1680
1681 if (normPathname[1] == ':') {
1682 return std::pair<std::string, std::string>(pathname.substr(0, 2), pathname.substr(2));
1683 }
1684 }
1685
1686 return std::pair<std::string, std::string>("", pathname);
1687#endif
1688}
1689
1742std::vector<std::string> vpIoTools::splitChain(const std::string &chain, const std::string &sep)
1743{
1744 size_t startIndex = 0;
1745
1746 std::string chainToSplit = chain;
1747 std::vector<std::string> subChain;
1748 size_t sepIndex = chainToSplit.find(sep);
1749
1750 while (sepIndex != std::string::npos) {
1751 std::string sub = chainToSplit.substr(startIndex, sepIndex);
1752 if (!sub.empty()) {
1753 subChain.push_back(sub);
1754 }
1755 chainToSplit = chainToSplit.substr(sepIndex + 1, chain.size() - 1);
1756
1757 sepIndex = chainToSplit.find(sep);
1758 }
1759 if (!chainToSplit.empty()) {
1760 subChain.push_back(chainToSplit);
1761 }
1762
1763 return subChain;
1764}
1765
1773std::vector<std::string> vpIoTools::getDirFiles(const std::string &pathname)
1774{
1775
1776 if (!checkDirectory(pathname)) {
1777 throw(vpIoException(vpException::fatalError, "Directory %s doesn't exist'", pathname.c_str()));
1778 }
1779 std::string dirName = path(pathname);
1780
1781#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1782
1783 std::vector<std::string> files;
1784 struct dirent **list = nullptr;
1785 int filesCount = scandir(dirName.c_str(), &list, nullptr, nullptr);
1786 if (filesCount == -1) {
1787 throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1788 }
1789 for (int i = 0; i < filesCount; ++i) {
1790 std::string fileName = list[i]->d_name;
1791 if ((fileName != ".") && (fileName != "..")) {
1792 files.push_back(fileName);
1793 }
1794 free(list[i]);
1795 }
1796 free(list);
1797 std::sort(files.begin(), files.end());
1798 return files;
1799
1800#elif defined(_WIN32)
1801#if (!defined(WINRT))
1802
1803 std::vector<std::string> files;
1804 std::string fileMask = dirName;
1805 fileMask.append("\\*");
1806 WIN32_FIND_DATA FindFileData;
1807 HANDLE hFind = FindFirstFile(fileMask.c_str(), &FindFileData);
1808 // Directory is empty
1809 if (HandleToLong(&hFind) == ERROR_FILE_NOT_FOUND) {
1810 return files;
1811 }
1812 if (hFind == INVALID_HANDLE_VALUE) {
1813 throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1814 }
1815 do {
1816 std::string fileName = FindFileData.cFileName;
1817 if (fileName != "." && fileName != "..") {
1818 files.push_back(fileName);
1819 }
1820 } while (FindNextFile(hFind, &FindFileData));
1821 FindClose(hFind);
1822 std::sort(files.begin(), files.end());
1823 return files;
1824
1825#else
1827 "Cannot read files of directory %s: not implemented on "
1828 "Universal Windows Platform",
1829 dirName.c_str()));
1830#endif
1831#endif
1832}
1833
1834END_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.
@ invalidDirectoryName
Directory name is invalid.
@ cantCreateDirectory
Unable to create a directory.
@ cantGetenv
Cannot get environment variable value.
static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
static std::string getViSPImagesDataPath()
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
static std::string path(const std::string &pathname)
static std::string getAbsolutePathname(const std::string &pathname)
static std::string toLowerCase(const std::string &input)
Return a lower-case version of the string input . Numbers and special characters stay the same.
static bool checkFilename(const std::string &filename)
static std::pair< std::string, std::string > splitDrive(const std::string &pathname)
static bool isSamePathname(const std::string &pathname1, const std::string &pathname2)
static std::string getTempPath()
static bool isAbsolutePathname(const std::string &pathname)
static bool copy(const std::string &src, const std::string &dst)
static bool checkDirectory(const std::string &dirname)
static std::string formatString(const std::string &name, unsigned int val)
static bool rename(const std::string &oldfilename, const std::string &newfilename)
static long getIndex(const std::string &filename, const std::string &format)
static std::string getUserName()
static std::string createFilePath(const std::string &parent, const std::string &child)
static std::string getenv(const std::string &env)
static std::string getFileExtension(const std::string &pathname, bool checkFile=false)
static std::vector< std::string > getDirFiles(const std::string &dirname)
static void makeDirectory(const std::string &dirname)
static bool remove(const std::string &filename)
static const std::string & getBuildInformation()
static std::string getNameWE(const std::string &pathname)
static std::string makeTempDirectory(const std::string &dirname)
static bool checkFifo(const std::string &filename)
static std::string getParent(const std::string &pathname)
static std::string getName(const std::string &pathname)
static std::string toUpperCase(const std::string &input)
Return a upper-case version of the string input . Numbers and special characters stay the same.
static const char separator
Definition vpIoTools.h:632
static void makeFifo(const std::string &dirname)