1 #define BIORBD_API_EXPORTS
2 #include "Utils/Path.h"
7 #include "Utils/String.h"
8 #include "Utils/Error.h"
20 m_originalPath(std::make_shared<biorbd::utils::
String>()),
21 m_folder(std::make_shared<biorbd::utils::
String>()),
22 m_isFolderAbsolute(std::make_shared<bool>()),
23 m_filename(std::make_shared<biorbd::utils::
String>()),
24 m_extension(std::make_shared<biorbd::utils::
String>())
31 m_originalPath(std::make_shared<biorbd::utils::
String>(path)),
32 m_folder(std::make_shared<biorbd::utils::
String>()),
33 m_isFolderAbsolute(std::make_shared<bool>()),
34 m_filename(std::make_shared<biorbd::utils::
String>()),
35 m_extension(std::make_shared<biorbd::utils::
String>())
43 m_originalPath(std::make_shared<biorbd::utils::
String>(path)),
44 m_folder(std::make_shared<biorbd::utils::
String>()),
45 m_isFolderAbsolute(std::make_shared<bool>()),
46 m_filename(std::make_shared<biorbd::utils::
String>()),
47 m_extension(std::make_shared<biorbd::utils::
String>())
54 const std::basic_string<char> &path) :
55 m_originalPath(std::make_shared<biorbd::utils::
String>(path)),
56 m_folder(std::make_shared<biorbd::utils::
String>()),
57 m_isFolderAbsolute(std::make_shared<bool>()),
58 m_filename(std::make_shared<biorbd::utils::
String>()),
59 m_extension(std::make_shared<biorbd::utils::
String>())
84 return isFileExist(absolutePath());
94 if (FILE *file = fopen(
96 toWindowsFormat(path).c_str(),
110 std::ifstream fichier(
112 toWindowsFormat(absolutePath()).c_str()
114 absolutePath().c_str()
117 bool isOpen(fichier.is_open());
124 return isFolderExist(*
this);
130 return isFolderExist(path.
folder());
137 if (GetFileAttributesA(toWindowsFormat(path).c_str())
138 == INVALID_FILE_ATTRIBUTES)
143 if (isFileExist(path))
149 if (stat(path.c_str(), &statbuf) != -1) {
166 size_t sepPos(pathSep.rfind(
"/"));
169 if (sepPos == std::string::npos)
174 folder = pathSep.substr(0, sepPos) +
"/";
176 if (folder.find(
"./") == 0)
177 folder = folder.substr(2);
180 size_t ext(pathSep.rfind(
"."));
182 extension = pathSep.substr(ext+1);
187 filename = pathSep.substr(sepPos+1, ext- sepPos-1);
191 return relativePath(*
this, currentDir());
197 return relativePath(*
this, relativeTo);
211 size_t sepMe = std::string::npos;
212 size_t sepCurrentDir = std::string::npos;
215 me = me.substr(sepMe+1);
216 currentDir = currentDir.substr(sepCurrentDir+1);
219 sepMe = me.find(
"/");
220 sepCurrentDir = currentDir.find(
"/");
223 meFirstPart = me.substr(0, sepMe);
224 currentDirFirstPart = currentDir.substr(0, sepCurrentDir);
228 }
while(!meFirstPart.compare(currentDirFirstPart));
231 while (currentDir.compare(
"")) {
234 sepCurrentDir = currentDir.find(
"/");
237 if (sepCurrentDir != std::string::npos){
240 currentDirFirstPart = currentDir.substr(0, sepCurrentDir);
241 currentDir = currentDir.substr(sepCurrentDir+1);
250 if (!outPath.compare(
"") && me.find(
"../") != 0)
270 if (std::regex_search(current, matches, std::regex(
"^([A-Z]):[\\/].*$"))) {
271 base = matches[1].str() +
":/";
279 return base + relativePath(path, base);
284 if (*m_isFolderAbsolute)
287 return currentDir() + *m_folder;
292 if (m_filename->compare(
"")){
293 if (m_extension->compare(
""))
294 return absoluteFolder() + *m_filename +
"." + *m_extension;
296 return absoluteFolder() + *m_filename;
298 return absoluteFolder();
308 size_t pos(pathOut.rfind(
"\\\\"));
309 while (pos != std::string::npos) {
310 pathOut.replace(pos, 2,
"/");
311 pos = pathOut.rfind(
"\\\\");
316 pos = pathOut.rfind(
"\\");
317 while (pos != std::string::npos) {
318 pathOut.replace(pos, 1,
"/");
319 pos = pathOut.rfind(
"\\");
328 size_t pos(pathOut.rfind(
"/"));
329 while (pos != std::string::npos) {
330 pathOut.replace(pos, 1,
"\\\\");
331 pos = pathOut.rfind(
"/");
338 return *m_originalPath;
375 if (std::regex_search(current, matches, std::regex(
"^([A-Z]):[\\/].*$"))) {
376 *m_isFolderAbsolute =
true;
379 *m_isFolderAbsolute =
false;
383 size_t pos(m_folder->find(base.c_str()));
385 *m_isFolderAbsolute =
true;
387 *m_isFolderAbsolute =
false;
393 char buff[FILENAME_MAX];
396 "Could not find the current directory");
399 "Could not find the current directory");
401 return toUnixFormat(buff) +
"/";
409 size_t sep = std::string::npos;
413 tp2 = tp2.substr(sep+1);
417 if (sep != std::string::npos){
418 sepTrack += sep + 1 ;
423 tp.substr(0, sepTrack)))) {
425 _mkdir(toWindowsFormat(tp.substr(0, sepTrack)).c_str());
427 mkdir(tp.substr(0, sepTrack).c_str(), 0777);
431 }
while (sep != std::string::npos);