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
138{
139 VP_ATTRIBUTE_NO_DESTROY static std::string build_info =
140#include "version_string.inc"
141 ;
142 return build_info;
143}
144
201{
202#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
203 std::string username;
204 vpIoTools::getUserName(username);
205 return "/tmp/" + username;
206#elif defined(_WIN32) && !defined(WINRT)
207 // https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-using-a-temporary-file
208 // Gets the temp path env string (no guarantee it's a valid path).
209 TCHAR lpTempPathBuffer[MAX_PATH];
210 DWORD dwRetVal = GetTempPath(MAX_PATH /* length of the buffer */, lpTempPathBuffer /* buffer for path */);
211 if (dwRetVal > MAX_PATH || (dwRetVal == 0)) {
212 throw vpIoException(vpIoException::cantGetenv, "Error with GetTempPath() call!");
213 }
214 std::string temp_path(lpTempPathBuffer);
215 if (!temp_path.empty()) {
216 if (temp_path.back() == '\\') {
217 temp_path.resize(temp_path.size() - 1);
218 }
219 }
220 else {
221 temp_path = "C:\temp";
222 try {
223 vpIoTools::makeDirectory(temp_path);
224 }
225 catch (...) {
226 throw(vpException(vpException::fatalError, "Cannot set temp path to %s", temp_path.c_str()));
227 }
228 }
229 return temp_path;
230#else
231 throw vpIoException(vpException::fatalError, "Not implemented on this platform!");
232#endif
233}
234
248void vpIoTools::getUserName(std::string &username)
249{
250 // With MinGW, UNIX and _WIN32 are defined
251#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
252 // Get the user name.
253 char *logname = ::getenv("LOGNAME");
254 if (!logname) {
255 username = "unknown";
256 }
257 else {
258 username = logname;
259 }
260#elif defined(_WIN32)
261#if (!defined(WINRT))
262 unsigned int info_buffer_size = 1024;
263 TCHAR *infoBuf = new TCHAR[info_buffer_size];
264 DWORD bufCharCount = static_cast<DWORD>(info_buffer_size);
265 // Get the user name.
266 if (!GetUserName(infoBuf, &bufCharCount)) {
267 username = "unknown";
268 }
269 else {
270 username = infoBuf;
271 }
272 delete[] infoBuf;
273#else
274 // Universal platform
275 username = "unknown";
276#endif
277#else
278 username = "unknown";
279#endif
280}
281
297{
298 std::string username;
299 getUserName(username);
300 return username;
301}
302
337std::string vpIoTools::getenv(const std::string &env)
338{
339#if defined(_WIN32) && defined(WINRT)
340 throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value: not "
341 "implemented on Universal Windows Platform"));
342#else
343 std::string value;
344 // Get the environment variable value.
345 char *v_value = ::getenv(env.c_str());
346 if (!v_value) {
347 throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value"));
348 }
349 value = v_value;
350
351 return value;
352#endif
353}
354
364void vpIoTools::getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
365{
366 if (version.size() == 0) {
367 major = 0;
368 minor = 0;
369 patch = 0;
370 }
371 else {
372 size_t major_pos = version.find('.');
373 std::string major_str = version.substr(0, major_pos);
374 major = static_cast<unsigned>(atoi(major_str.c_str()));
375
376 if (major_pos != std::string::npos) {
377 size_t minor_pos = version.find('.', major_pos + 1);
378 std::string minor_str = version.substr(major_pos + 1, (minor_pos - (major_pos + 1)));
379 minor = static_cast<unsigned>(atoi(minor_str.c_str()));
380
381 if (minor_pos != std::string::npos) {
382 std::string patch_str = version.substr(minor_pos + 1);
383 patch = static_cast<unsigned>(atoi(patch_str.c_str()));
384 }
385 else {
386 patch = 0;
387 }
388 }
389 else {
390 minor = 0;
391 patch = 0;
392 }
393 }
394}
395
407bool vpIoTools::checkDirectory(const std::string &dirname)
408{
409#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
410 struct stat stbuf;
411#elif defined(_WIN32) && defined(__MINGW32__)
412 struct stat stbuf;
413#elif defined(_WIN32)
414 struct _stat stbuf;
415#endif
416
417 if (dirname.empty()) {
418 return false;
419 }
420
421 std::string path_dirname = path(dirname);
422
423 if (VP_STAT(path_dirname.c_str(), &stbuf) != 0) {
424 // Test adding the separator if not already present
425 if (path_dirname.at(path_dirname.size() - 1) != separator) {
426 if (VP_STAT((path_dirname + separator).c_str(), &stbuf) != 0) {
427 return false;
428 }
429 }
430 // Test removing the separator if already present
431 if (path_dirname.at(path_dirname.size() - 1) == separator) {
432 if (VP_STAT((path_dirname.substr(0, path_dirname.size() - 1)).c_str(), &stbuf) != 0) {
433 return false;
434 }
435 }
436 }
437
438#if defined(_WIN32) || (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
439 if ((stbuf.st_mode & S_IFDIR) == 0)
440#endif
441 {
442 return false;
443 }
444#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
445 if ((stbuf.st_mode & S_IWUSR) == 0)
446#elif defined(_WIN32)
447 if ((stbuf.st_mode & S_IWRITE) == 0)
448#endif
449 {
450 return false;
451 }
452 return true;
453}
454
467bool vpIoTools::checkFifo(const std::string &fifofilename)
468{
469#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
470 struct stat stbuf;
471
472 std::string v_filename = path(fifofilename);
473 if (stat(v_filename.c_str(), &stbuf) != 0) {
474 return false;
475 }
476 if ((stbuf.st_mode & S_IFIFO) == 0) {
477 return false;
478 }
479 if ((stbuf.st_mode & S_IRUSR) == 0)
480
481 {
482 return false;
483 }
484 return true;
485#elif defined(_WIN32)
486 (void)fifofilename;
487 throw(vpIoException(vpIoException::notImplementedError, "Fifo files are not supported on Windows platforms."));
488#endif
489}
490
491#ifndef DOXYGEN_SHOULD_SKIP_THIS
492int vpIoTools::mkdir_p(const std::string &path, int mode)
493{
494 errno = 0;
495 if (path.size() > PATH_MAX) {
496 errno = ENAMETOOLONG;
497 return -1;
498 }
499
500 // Iterate over the string
501 std::string cpy_path = path;
502 std::string sub_path;
503 size_t pos = 0;
504 while (pos != std::string::npos) {
505 sub_path += cpy_path.substr(0, pos + 1);
506 // Continue if sub_path = separator
507 bool stop_for_loop = false;
508 if (pos == 0) {
509 cpy_path.erase(0, pos + 1);
510 stop_for_loop = true;
511 }
512 if (!stop_for_loop) {
513#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
514 if (mkdir(sub_path.c_str(), static_cast<mode_t>(mode)) != 0)
515#elif defined(_WIN32)
516 (void)mode; // var not used
517 if (!checkDirectory(sub_path) && _mkdir(sub_path.c_str()) != 0)
518#endif
519 {
520 if (errno != EEXIST) {
521 return -1;
522 }
523 }
524 cpy_path.erase(0, pos + 1);
525 }
526 pos = cpy_path.find(vpIoTools::separator);
527 }
528
529 if (!cpy_path.empty()) {
530 sub_path += cpy_path;
531#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
532 if (mkdir(sub_path.c_str(), static_cast<mode_t>(mode)) != 0)
533#elif defined(_WIN32)
534
535 if (_mkdir(sub_path.c_str()) != 0)
536#endif
537 {
538 if (errno != EEXIST) {
539 return -1;
540 }
541 }
542 }
543
544 return 0;
545}
546
547#endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
548
561void vpIoTools::makeDirectory(const std::string &dirname)
562{
563#if ((!defined(__unix__) && !defined(__unix) && (!defined(__APPLE__) || !defined(__MACH__)))) && !defined(_WIN32)
564 std::cerr << "Unsupported platform for vpIoTools::makeDirectory()!" << std::endl;
565 return;
566#endif
567
568#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
569 struct stat stbuf;
570#elif defined(_WIN32) && defined(__MINGW32__)
571 struct stat stbuf;
572#elif defined(_WIN32)
573 struct _stat stbuf;
574#endif
575
576 if (dirname.empty()) {
577 throw(vpIoException(vpIoException::invalidDirectoryName, "invalid directory name"));
578 }
579
580 std::string v_dirname = path(dirname);
581
582#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
583 if (stat(v_dirname.c_str(), &stbuf) != 0)
584#elif defined(_WIN32) && defined(__MINGW32__)
585 if (stat(v_dirname.c_str(), &stbuf) != 0)
586#elif defined(_WIN32)
587 if (_stat(v_dirname.c_str(), &stbuf) != 0)
588#endif
589 {
590 if (vpIoTools::mkdir_p(v_dirname, 0755) != 0) {
591 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str()));
592 }
593 }
594
595 if (checkDirectory(dirname) == false) {
596 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str()));
597 }
598}
599
612void vpIoTools::makeFifo(const std::string &fifoname)
613{
614#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
615
616 // If dirname is a directory, we throw an error
617 if (vpIoTools::checkDirectory(fifoname)) {
619 "Unable to create fifo file. '%s' is an existing directory.", fifoname.c_str()));
620 }
621
622 // If dirname refers to an already existing file, we throw an error
623 else if (vpIoTools::checkFilename(fifoname)) {
624 throw(vpIoException(vpIoException::invalidDirectoryName, "Unable to create fifo file '%s'. File already exists.",
625 fifoname.c_str()));
626 // If dirname refers to an already existing fifo, we throw an error
627 }
628 else if (vpIoTools::checkFifo(fifoname)) {
629 throw(vpIoException(vpIoException::invalidDirectoryName, "Unable to create fifo file '%s'. Fifo already exists.",
630 fifoname.c_str()));
631 }
632
633 else if (mkfifo(fifoname.c_str(), 0666) < 0) {
634 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create fifo file '%s'.", fifoname.c_str()));
635 }
636#elif defined(_WIN32)
637 (void)fifoname;
638 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create fifo on Windows platforms."));
639#endif
640}
641
642#if defined(_WIN32) && !defined(WINRT)
643std::string getUuid();
644
645std::string getUuid()
646{
647 UUID uuid;
648 if (UuidCreate(&uuid) != RPC_S_OK) {
649 throw(vpIoException(vpIoException::fatalError, "UuidCreate() failed!"));
650 }
651
652 RPC_CSTR stringUuid;
653 if (UuidToString(&uuid, &stringUuid) != RPC_S_OK) {
654 throw(vpIoException(vpIoException::fatalError, "UuidToString() failed!"));
655 }
656
657 return reinterpret_cast<char *>(stringUuid);
658}
659#endif
660
721std::string vpIoTools::makeTempDirectory(const std::string &dirname)
722{
723#if defined(WINRT) || !defined(_WIN32) && !(defined(__unix__) || defined(__unix) || \
724 (defined(__APPLE__) && defined(__MACH__))) // not UNIX and not Windows
725 throw(vpIoException(vpIoException::cantCreateDirectory, "makeTempDirectory() is not supported on this platform!"));
726#endif
727
728 std::string dirname_cpy = std::string(dirname);
729 std::string correctEnding = "XXXXXX";
730
731 // If dirname is an unexisting directory, it should end with XXXXXX in order to create a temp directory
732 if (!vpIoTools::checkDirectory(dirname_cpy)) {
733#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
734 // Check if dirname ends with XXXXXX
735 if (dirname_cpy.rfind(correctEnding) == std::string::npos) {
736 if (dirname_cpy.at(dirname_cpy.length() - 1) != '/') {
737 dirname_cpy = dirname_cpy + "/";
738 }
739 try {
740 vpIoTools::makeDirectory(dirname_cpy);
741 }
742 catch (...) {
743 throw(vpException(vpException::fatalError, "Cannot create temp directory %s", dirname_cpy.c_str()));
744 }
745
746 dirname_cpy = dirname_cpy + "XXXXXX";
747 }
748
749#elif defined(_WIN32) && !defined(WINRT)
750 // Remove XXXXXX
751 dirname_cpy = dirname_cpy.substr(0, dirname_cpy.rfind(correctEnding));
752 // Append UUID
753 dirname_cpy = dirname_cpy + getUuid();
754#endif
755
756 }
757 else {
758 // If dirname is an existing directory, we create a temp directory inside
759#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
760 if (dirname_cpy.at(dirname_cpy.length() - 1) != '/') {
761 dirname_cpy = dirname_cpy + "/";
762 }
763 dirname_cpy = dirname_cpy + "XXXXXX";
764#elif defined(_WIN32) && !defined(WINRT)
765 dirname_cpy = createFilePath(dirname_cpy, getUuid());
766#endif
767 }
768
769#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
770 char *dirname_char = new char[dirname_cpy.length() + 1];
771 strcpy(dirname_char, dirname_cpy.c_str());
772
773 char *computedDirname = mkdtemp(dirname_char);
774
775 if (!computedDirname) {
776 delete[] dirname_char;
777 throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'.", dirname_cpy.c_str()));
778 }
779
780 std::string res(computedDirname);
781 delete[] dirname_char;
782 return res;
783#elif defined(_WIN32) && !defined(WINRT)
784 makeDirectory(dirname_cpy);
785 return dirname_cpy;
786#endif
787}
788
799bool vpIoTools::checkFilename(const std::string &filename)
800{
801#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
802 struct stat stbuf;
803#elif defined(_WIN32)
804 struct _stat stbuf;
805#endif
806
807 if (filename.empty()) {
808 return false;
809 }
810
811 std::string v_filename = path(filename);
812#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
813 if (stat(v_filename.c_str(), &stbuf) != 0)
814#elif defined(_WIN32)
815 if (_stat(v_filename.c_str(), &stbuf) != 0)
816#endif
817 {
818 return false;
819 }
820 if ((stbuf.st_mode & S_IFREG) == 0) {
821 return false;
822 }
823#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
824 if ((stbuf.st_mode & S_IRUSR) == 0)
825#elif defined(_WIN32)
826 if ((stbuf.st_mode & S_IREAD) == 0)
827#endif
828 {
829 return false;
830 }
831 return true;
832}
833
841bool vpIoTools::copy(const std::string &src, const std::string &dst)
842{
843 // Check if we have to consider a file or a directory
844 if (vpIoTools::checkFilename(src)) {
845 // --comment: std::cout "copy file: " src " in " dst std::endl;
846#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
847#if TARGET_OS_IOS == 0 // The following code is not working on iOS since
848 // wordexp() is not available
849 std::stringstream cmd;
850 cmd << "cp -p ";
851 cmd << src;
852 cmd << " ";
853 cmd << dst;
854 int ret = system(cmd.str().c_str());
855 if (ret) {
856 } // to avoid a warning
857 // std::cout << cmd << " return value: " << ret << std::endl;
858 return true;
859#else
860 throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src.c_str(),
861 dst.c_str()));
862#endif
863#elif defined(_WIN32)
864#if (!defined(WINRT))
865 std::stringstream cmd;
866 cmd << "copy ";
867 cmd << vpIoTools::path(src);
868 cmd << " ";
869 cmd << vpIoTools::path(dst);
870 int ret = system(cmd.str().c_str());
871 if (ret) {
872 } // to avoid a warning
873 // std::cout << cmd << " return value: " << ret << std::endl;
874 return true;
875#else
876 throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
877 src.c_str(), dst.c_str()));
878#endif
879#endif
880 }
881 else if (vpIoTools::checkDirectory(src)) {
882 // --comment: std::cout "copy directory: " src " in " dst
883#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
884#if TARGET_OS_IOS == 0 // The following code is not working on iOS since
885 // wordexp() is not available
886 std::stringstream cmd;
887 cmd << "cp -p ";
888 cmd << src;
889 cmd << " ";
890 cmd << dst;
891 int ret = system(cmd.str().c_str());
892 if (ret) {
893 } // to avoid a warning
894 // std::cout << cmd << " return value: " << ret << std::endl;
895 return true;
896#else
897 throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src.c_str(),
898 dst.c_str()));
899#endif
900#elif defined(_WIN32)
901#if (!defined(WINRT))
902 std::stringstream cmd;
903 cmd << "copy ";
904 cmd << vpIoTools::path(src);
905 cmd << " ";
906 cmd << vpIoTools::path(dst);
907 int ret = system(cmd.str().c_str());
908 if (ret) {
909 } // to avoid a warning
910 // std::cout << cmd << " return value: " << ret << std::endl;
911 return true;
912#else
913 throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
914 src.c_str(), dst.c_str()));
915#endif
916#endif
917 }
918 else {
919 std::cout << "Cannot copy: " << src << " in " << dst << std::endl;
920 return false;
921 }
922}
923
934bool vpIoTools::remove(const std::string &file_or_dir)
935{
936 // Check if we have to consider a file or a directory
937 if (vpIoTools::checkFilename(file_or_dir)
938#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
939 || vpIoTools::checkFifo(std::string(file_or_dir))
940#endif
941 ) {
942 if (::remove(file_or_dir.c_str()) != 0) {
943 return false;
944 }
945 else {
946 return true;
947 }
948 }
949 else if (vpIoTools::checkDirectory(file_or_dir)) {
950#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
951#if TARGET_OS_IOS == 0 // The following code is not working on iOS since
952 // wordexp() is not available
953 std::stringstream cmd;
954 cmd << "rm -rf \"";
955 cmd << file_or_dir;
956 cmd << "\"";
957 int ret = system(cmd.str().c_str());
958 if (ret) {
959 } // to avoid a warning
960 // std::cout << cmd << " return value: " << ret << std::endl;
961 return true;
962#else
963 throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on iOS Platform",
964 file_or_dir.c_str()));
965#endif
966#elif defined(_WIN32)
967#if (!defined(WINRT))
968 std::stringstream cmd;
969 cmd << "rmdir /S /Q ";
970 cmd << vpIoTools::path(file_or_dir);
971 cmd << "\"";
972 int ret = system(cmd.str().c_str());
973 if (ret) {
974 } // to avoid a warning
975 // std::cout << cmd << " return value: " << ret << std::endl;
976 return true;
977#else
978 throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on Universal Windows Platform",
979 file_or_dir.c_str()));
980#endif
981#endif
982 }
983 else {
984 std::cout << "Cannot remove: " << file_or_dir << std::endl;
985 return false;
986 }
987}
988
998bool vpIoTools::rename(const std::string &oldfilename, const std::string &newfilename)
999{
1000 if (::rename(oldfilename.c_str(), newfilename.c_str()) != 0) {
1001 return false;
1002 }
1003 else {
1004 return true;
1005 }
1006}
1007
1018std::string vpIoTools::path(const std::string &pathname)
1019{
1020 std::string path(pathname);
1021
1022#if defined(_WIN32)
1023 for (unsigned int i = 0; i < path.length(); ++i)
1024 if (path[i] == '/')
1025 path[i] = '\\';
1026#elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
1027 unsigned int path_length = path.length();
1028 for (unsigned int i = 0; i < path_length; ++i) {
1029 if (path[i] == '\\') {
1030 path[i] = '/';
1031 }
1032 }
1033#if TARGET_OS_IOS == 0 // The following code is not working on iOS and android since
1034 // wordexp() is not available
1035#ifdef __ANDROID__
1036// Do nothing
1037#else
1038 wordexp_t exp_result;
1039
1040 // escape quote character
1041 replaceAll(path, "'", "'\\''");
1042 // add quotes to handle special characters like parentheses and spaces
1043 wordexp(std::string("'" + path + "'").c_str(), &exp_result, 0);
1044 path = exp_result.we_wordc == 1 ? exp_result.we_wordv[0] : "";
1045 wordfree(&exp_result);
1046#endif
1047#endif
1048#endif
1049
1050 return path;
1051}
1052
1067{
1068 std::string data_path;
1069 std::string file_to_test("mbt/cube.cao");
1070 std::string filename;
1071 // Test if VISP_INPUT_IMAGE_PATH env var is set
1072 try {
1073 data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH");
1074 filename = data_path + "/" + file_to_test;
1075 if (vpIoTools::checkFilename(filename)) {
1076 return data_path;
1077 }
1078 }
1079 catch (...) {
1080 }
1081 try {
1082 data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/ViSP-images";
1083 filename = data_path + "/" + file_to_test;
1084 if (vpIoTools::checkFilename(filename)) {
1085 return data_path;
1086 }
1087 }
1088 catch (...) {
1089 }
1090 try {
1091 data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/visp-images";
1092 filename = data_path + "/" + file_to_test;
1093 if (vpIoTools::checkFilename(filename)) {
1094 return data_path;
1095 }
1096 }
1097 catch (...) {
1098 }
1099
1100#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1101 // Test if visp-images-data package is installed (Ubuntu and Debian)
1102 data_path = "/usr/share/visp-images-data/ViSP-images";
1103 filename = data_path + "/" + file_to_test;
1104 if (vpIoTools::checkFilename(filename)) {
1105 return data_path;
1106 }
1107 data_path = "/usr/share/visp-images-data/visp-images";
1108 filename = data_path + "/" + file_to_test;
1109 if (vpIoTools::checkFilename(filename)) {
1110 return data_path;
1111 }
1112#endif
1113 data_path = "";
1114 return data_path;
1115}
1116
1149std::string vpIoTools::getFileExtension(const std::string &pathname, bool checkFile)
1150{
1151 if (checkFile && (vpIoTools::checkDirectory(pathname) || (!vpIoTools::checkFilename(pathname)))) {
1152 return "";
1153 }
1154
1155#if defined(_WIN32)
1156 std::string sep = "\\";
1157 std::string altsep = "/";
1158 std::string extsep = ".";
1159#else
1160 // On Unix, or on the Mac
1161 std::string sep = "/";
1162 std::string altsep = "";
1163 std::string extsep = ".";
1164#endif
1165
1166 // Python 2.7.8 module.
1167 // # Split a path in root and extension.
1168 // # The extension is everything starting at the last dot in the last
1169 // # pathname component; the root is everything before that.
1170 // # It is always true that root + ext == p.
1171 //
1172 // # Generic implementation of splitext, to be parametrized with
1173 // # the separators
1174 // def _splitext(p, sep, altsep, extsep):
1175 // """Split the extension from a pathname.
1176 //
1177 // Extension is everything from the last dot to the end, ignoring
1178 // leading dots. Returns "(root, ext)"; ext may be empty."""
1179 //
1180 // sepIndex = p.rfind(sep)
1181 // if altsep:
1182 // altsepIndex = p.rfind(altsep)
1183 // sepIndex = max(sepIndex, altsepIndex)
1184 //
1185 // dotIndex = p.rfind(extsep)
1186 // if dotIndex > sepIndex:
1187 // # skip all leading dots
1188 // filenameIndex = sepIndex + 1
1189 // while filenameIndex < dotIndex:
1190 // if p[filenameIndex] != extsep:
1191 // return p[:dotIndex], p[dotIndex:]
1192 // filenameIndex += 1
1193 //
1194 // return p, ''
1195
1196 int sepIndex = static_cast<int>(pathname.rfind(sep));
1197 if (!altsep.empty()) {
1198 int altsepIndex = static_cast<int>(pathname.rfind(altsep));
1199 sepIndex = std::max<int>(sepIndex, altsepIndex);
1200 }
1201
1202 size_t dotIndex = pathname.rfind(extsep);
1203 if (dotIndex != std::string::npos) {
1204 // The extsep character exists
1205 size_t npos = std::string::npos;
1206 if (((sepIndex != static_cast<int>(npos)) && (static_cast<int>(dotIndex) > sepIndex)) ||
1207 (sepIndex == static_cast<int>(npos))) {
1208 if (sepIndex == static_cast<int>(npos)) {
1209 sepIndex = 0;
1210 }
1211 size_t filenameIndex = static_cast<size_t>(sepIndex) + static_cast<size_t>(1);
1212
1213 while (filenameIndex < dotIndex) {
1214 if (pathname.compare(filenameIndex, 1, extsep) != 0) {
1215 return pathname.substr(dotIndex);
1216 }
1217 filenameIndex++;
1218 }
1219 }
1220 }
1221
1222 return "";
1223}
1224
1230std::string vpIoTools::getName(const std::string &pathname)
1231{
1232 if (pathname.size() > 0) {
1233 std::string convertedPathname = vpIoTools::path(pathname);
1234
1235 size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1236 if (index != std::string::npos) {
1237 return convertedPathname.substr(index + 1);
1238 }
1239
1240 return convertedPathname;
1241 }
1242
1243 return "";
1244}
1245
1252std::string vpIoTools::getNameWE(const std::string &pathname)
1253{
1254 std::string name = vpIoTools::getName(pathname);
1255 size_t found = name.find_last_of(".");
1256 std::string name_we = name.substr(0, found);
1257 return name_we;
1258}
1259
1297long vpIoTools::getIndex(const std::string &filename, const std::string &format)
1298{
1299 size_t indexBegin = format.find_last_of('%');
1300 size_t indexEnd = format.find_first_of('d', indexBegin);
1301 size_t suffixLength = format.length() - indexEnd - 1;
1302 // Extracting index
1303 if (filename.length() <= (suffixLength + indexBegin)) {
1304 return -1;
1305 }
1306 size_t indexLength = filename.length() - suffixLength - indexBegin;
1307 std::string indexSubstr = filename.substr(indexBegin, indexLength);
1308 std::istringstream ss(indexSubstr);
1309 long index = 0;
1310 ss >> index;
1311 if (ss.fail() || (index < 0) || (!ss.eof())) {
1312 return -1;
1313 }
1314
1315 // Checking that format with inserted index equals filename
1316 char nameByFormat[FILENAME_MAX];
1317 snprintf(nameByFormat, FILENAME_MAX, format.c_str(), index);
1318 if (std::string(nameByFormat) != filename) {
1319 return -1;
1320 }
1321 return index;
1322}
1323
1339std::string vpIoTools::getParent(const std::string &pathname)
1340{
1341 if (pathname.size() > 0) {
1342 std::string convertedPathname = vpIoTools::path(pathname);
1343
1344 size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1345 if (index != std::string::npos) {
1346 return convertedPathname.substr(0, index);
1347 }
1348
1349 return ".";
1350 }
1351 else {
1352 return "";
1353 }
1354}
1355
1364std::string vpIoTools::toLowerCase(const std::string &input)
1365{
1366 std::string out;
1367#if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1368 const std::string::const_iterator it_end = input.cend();
1369 for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) {
1370#else
1371 const std::string::const_iterator it_end = input.end();
1372 for (std::string::const_iterator it = input.begin(); it != it_end; ++it) {
1373#endif
1374 out += std::tolower(*it);
1375 }
1376 return out;
1377}
1378
1387std::string vpIoTools::toUpperCase(const std::string &input)
1388{
1389 std::string out;
1390#if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1391 const std::string::const_iterator it_end = input.cend();
1392 for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) {
1393#else
1394 const std::string::const_iterator it_end = input.end();
1395 for (std::string::const_iterator it = input.begin(); it != it_end; ++it) {
1396#endif
1397 out += std::toupper(*it);
1398 }
1399 return out;
1400}
1401
1436std::string vpIoTools::formatString(const std::string &name, unsigned int val)
1437{
1438 const char *fmt = name.c_str();
1439 int sz = std::snprintf(nullptr, 0, fmt, val);
1440 sz += 1; // note +1 for null terminator
1441 std::vector<char> buf(sz);
1442 std::snprintf(buf.data(), sz, fmt, val);
1443 std::string str(buf.begin(), buf.end());
1444#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1445 str.pop_back(); // Only since cxx11
1446#else
1447 str.erase(str.end()-1, str.end());
1448#endif
1449 return str;
1450}
1451
1460std::string vpIoTools::getAbsolutePathname(const std::string &pathname)
1461{
1462
1463#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1464 std::string real_path_str = pathname;
1465 char *real_path = realpath(pathname.c_str(), nullptr);
1466
1467 if (real_path) {
1468 real_path_str = real_path;
1469 free(real_path);
1470 }
1471 return real_path_str;
1472#elif defined(_WIN32)
1473#if (!defined(WINRT))
1474 std::string real_path_str = pathname;
1475 DWORD retval = 0;
1476 TCHAR buffer[4096] = TEXT("");
1477
1478 retval = GetFullPathName(pathname.c_str(), 4096, buffer, 0);
1479 if (retval != 0) {
1480 real_path_str = buffer;
1481 }
1482 return real_path_str;
1483#else
1485 "Cannot get absolute path of %s: not implemented on "
1486 "Universal Windows Platform",
1487 pathname.c_str()));
1488#endif
1489#endif
1490}
1491
1502std::string vpIoTools::createFilePath(const std::string &parent, const std::string &child)
1503{
1504 if ((child.size() == 0) && (parent.size() == 0)) {
1505 return "";
1506 }
1507
1508 if (child.size() == 0) {
1509 return vpIoTools::path(parent);
1510 }
1511
1512 if (parent.size() == 0) {
1513 return vpIoTools::path(child);
1514 }
1515
1516 std::string convertedParent = vpIoTools::path(parent);
1517 std::string convertedChild = vpIoTools::path(child);
1518
1519 std::stringstream ss;
1521 std::string stringSeparator;
1522 ss >> stringSeparator;
1523
1524 std::string lastConvertedParentChar = convertedParent.substr(convertedParent.size() - 1);
1525 std::string firstConvertedChildChar = convertedChild.substr(0, 1);
1526
1527 if (lastConvertedParentChar == stringSeparator) {
1528 convertedParent = convertedParent.substr(0, convertedParent.size() - 1);
1529 }
1530
1531 if (firstConvertedChildChar == stringSeparator) {
1532 convertedChild = convertedChild.substr(1);
1533 }
1534
1535 return std::string(convertedParent + vpIoTools::separator + convertedChild);
1536}
1537
1543bool vpIoTools::isAbsolutePathname(const std::string &pathname)
1544{
1545 // # Inspired by the Python 2.7.8 module.
1546 // # Return whether a path is absolute.
1547 // # Trivial in Posix, harder on the Mac or MS-DOS.
1548 // # For DOS it is absolute if it starts with a slash or backslash (current
1549 // # volume), or if a pathname after the volume letter and colon / UNC
1550 // resource # starts with a slash or backslash.
1551 //
1552 // def isabs(s):
1553 // """Test whether a path is absolute"""
1554 // s = splitdrive(s)[1]
1555 // return s != '' and s[:1] in '/\\'
1556 std::string path = splitDrive(pathname).second;
1557 return (path.size() > 0) && ((path.substr(0, 1) == "/") || (path.substr(0, 1) == "\\"));
1558}
1559
1567bool vpIoTools::isSamePathname(const std::string &pathname1, const std::string &pathname2)
1568{
1569 // Normalize path
1570 std::string path1_normalize = vpIoTools::path(pathname1);
1571 std::string path2_normalize = vpIoTools::path(pathname2);
1572
1573 // Get absolute path
1574 path1_normalize = vpIoTools::getAbsolutePathname(path1_normalize);
1575 path2_normalize = vpIoTools::getAbsolutePathname(path2_normalize);
1576
1577 return (path1_normalize == path2_normalize);
1578}
1579
1587std::pair<std::string, std::string> vpIoTools::splitDrive(const std::string &pathname)
1588{
1589 // # Split a path in a drive specification (a drive letter followed by a
1590 // # colon) and the path specification.
1591 // # It is always true that drivespec + pathspec == p
1592 // def splitdrive(p):
1593 // """Split a pathname into drive/UNC sharepoint and relative path
1594 // specifiers. Returns a 2-tuple (drive_or_unc, path); either part may be
1595 // empty.
1596 //
1597 // If you assign
1598 // result = splitdrive(p)
1599 // It is always true that:
1600 // result[0] + result[1] == p
1601 //
1602 // If the path contained a drive letter, drive_or_unc will contain
1603 // everything up to and including the colon. e.g. splitdrive("c:/dir")
1604 // returns ("c:", "/dir")
1605 //
1606 // If the path contained a UNC path, the drive_or_unc will contain the host
1607 // name and share up to but not including the fourth directory separator
1608 // character. e.g. splitdrive("//host/computer/dir") returns
1609 // ("//host/computer", "/dir")
1610 //
1611 // Paths cannot contain both a drive letter and a UNC path.
1612 //
1613 // """
1614 // if len(p) > 1:
1615 // normp = p.replace(altsep, sep)
1616 // if (normp[0:2] == sep*2) and (normp[2] != sep):
1617 // # is a UNC path:
1618 // # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1619 // # \\machine\mountpoint\directory\etc\...
1620 // # directory ^^^^^^^^^^^^^^^
1621 // index = normp.find(sep, 2)
1622 // if index == -1:
1623 // return '', p
1624 // index2 = normp.find(sep, index + 1)
1625 // # a UNC path can't have two slashes in a row
1626 // # (after the initial two)
1627 // if index2 == index + 1:
1628 // return '', p
1629 // if index2 == -1:
1630 // index2 = len(p)
1631 // return p[:index2], p[index2:]
1632 // if normp[1] == ':':
1633 // return p[:2], p[2:]
1634 // return '', p
1635
1636 // On Unix, the drive is always empty.
1637 // On the Mac, the drive is always empty (don't use the volume name -- it
1638 // doesn't have the same syntactic and semantic oddities as DOS drive
1639 // letters, such as there being a separate current directory per drive).
1640#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1641 return std::pair<std::string, std::string>("", pathname);
1642#else
1643 const std::string sep = "\\";
1644 const std::string sepsep = "\\\\";
1645 const std::string altsep = "/";
1646
1647 if (pathname.size() > 1) {
1648 std::string normPathname = pathname;
1649 std::replace(normPathname.begin(), normPathname.end(), *altsep.c_str(), *sep.c_str());
1650
1651 if (normPathname.substr(0, 2) == sepsep && normPathname.substr(2, 1) != sep) {
1652 // is a UNC path:
1653 // vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1654 // \\machine\mountpoint\directory\etc\...
1655 // directory ^^^^^^^^^^^^^^^
1656 size_t index = normPathname.find(sep, 2);
1657 if (index == std::string::npos) {
1658 return std::pair<std::string, std::string>("", pathname);
1659 }
1660
1661 size_t index2 = normPathname.find(sep, index + 1);
1662 // # a UNC path can't have two slashes in a row
1663 // # (after the initial two)
1664 if (index2 == index + 1) {
1665 return std::pair<std::string, std::string>("", pathname);
1666 }
1667
1668 if (index2 == std::string::npos) {
1669 index2 = pathname.size();
1670 }
1671
1672 return std::pair<std::string, std::string>(pathname.substr(0, index2), pathname.substr(index2));
1673 }
1674
1675 if (normPathname[1] == ':') {
1676 return std::pair<std::string, std::string>(pathname.substr(0, 2), pathname.substr(2));
1677 }
1678 }
1679
1680 return std::pair<std::string, std::string>("", pathname);
1681#endif
1682}
1683
1736std::vector<std::string> vpIoTools::splitChain(const std::string &chain, const std::string &sep)
1737{
1738 size_t startIndex = 0;
1739
1740 std::string chainToSplit = chain;
1741 std::vector<std::string> subChain;
1742 size_t sepIndex = chainToSplit.find(sep);
1743
1744 while (sepIndex != std::string::npos) {
1745 std::string sub = chainToSplit.substr(startIndex, sepIndex);
1746 if (!sub.empty()) {
1747 subChain.push_back(sub);
1748 }
1749 chainToSplit = chainToSplit.substr(sepIndex + 1, chain.size() - 1);
1750
1751 sepIndex = chainToSplit.find(sep);
1752 }
1753 if (!chainToSplit.empty()) {
1754 subChain.push_back(chainToSplit);
1755 }
1756
1757 return subChain;
1758}
1759
1767std::vector<std::string> vpIoTools::getDirFiles(const std::string &pathname)
1768{
1769
1770 if (!checkDirectory(pathname)) {
1771 throw(vpIoException(vpException::fatalError, "Directory %s doesn't exist'", pathname.c_str()));
1772 }
1773 std::string dirName = path(pathname);
1774
1775#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1776
1777 std::vector<std::string> files;
1778 struct dirent **list = nullptr;
1779 int filesCount = scandir(dirName.c_str(), &list, nullptr, nullptr);
1780 if (filesCount == -1) {
1781 throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1782 }
1783 for (int i = 0; i < filesCount; ++i) {
1784 std::string fileName = list[i]->d_name;
1785 if ((fileName != ".") && (fileName != "..")) {
1786 files.push_back(fileName);
1787 }
1788 free(list[i]);
1789 }
1790 free(list);
1791 std::sort(files.begin(), files.end());
1792 return files;
1793
1794#elif defined(_WIN32)
1795#if (!defined(WINRT))
1796
1797 std::vector<std::string> files;
1798 std::string fileMask = dirName;
1799 fileMask.append("\\*");
1800 WIN32_FIND_DATA FindFileData;
1801 HANDLE hFind = FindFirstFile(fileMask.c_str(), &FindFileData);
1802 // Directory is empty
1803 if (HandleToLong(&hFind) == ERROR_FILE_NOT_FOUND) {
1804 return files;
1805 }
1806 if (hFind == INVALID_HANDLE_VALUE) {
1807 throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1808 }
1809 do {
1810 std::string fileName = FindFileData.cFileName;
1811 if (fileName != "." && fileName != "..") {
1812 files.push_back(fileName);
1813 }
1814 } while (FindNextFile(hFind, &FindFileData));
1815 FindClose(hFind);
1816 std::sort(files.begin(), files.end());
1817 return files;
1818
1819#else
1821 "Cannot read files of directory %s: not implemented on "
1822 "Universal Windows Platform",
1823 dirName.c_str()));
1824#endif
1825#endif
1826}
1827
1828END_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)