| 59 | } |
| 60 | |
| 61 | path completePathToFile(const path& p, const path& base, const std::string& ext, bool warnOnMismatch) { |
| 62 | path result(p); |
| 63 | |
| 64 | // handle file extension |
| 65 | if (!ext.empty()) { |
| 66 | result = setFileExtension(p, ext, false, warnOnMismatch); |
| 67 | if (result.empty()) { |
| 68 | result = p; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // complete path |
| 73 | if (!result.is_complete()) { |
| 74 | try { |
| 75 | if (!base.empty()) { |
| 76 | result = openstudio::filesystem::complete(result, base); |
| 77 | } else { |
| 78 | result = openstudio::filesystem::complete(result); |
| 79 | } |
| 80 | } catch (...) { |
| 81 | LOG_FREE(Info, "openstudio.completePathToFile", "Unable to compete path '" << toString(p) << "'. Returning an empty path."); |
| 82 | return {}; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // check that result is a file |
| 87 | if (!openstudio::filesystem::is_regular_file(result)) { |
| 88 | LOG_FREE(Info, "openstudio.completePathToFile", |
| 89 | "Path '" << toString(p) << "' could not be resolved to an existing file. Returning an empty path."); |
| 90 | return {}; |
| 91 | } |
| 92 | |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | std::string getFileExtension(const path& p) { |
| 97 | std::string pext = openstudio::filesystem::extension(p); |