Skip to content

Commit 0a567fb

Browse files
authored
ofFile::doesFileExist simplified (#7970)
#changelog #utils
1 parent 0722250 commit 0a567fb

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

libs/openFrameworks/utils/ofFileUtils.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,14 +1126,15 @@ bool ofFile::moveFromTo(const fs::path& pathSrc, const fs::path& pathDst, bool b
11261126
}
11271127

11281128
//------------------------------------------------------------------------------------------------------------
1129-
bool ofFile::doesFileExist(const fs::path& _fPath, bool bRelativeToData){
1130-
ofFile tmp;
1129+
bool ofFile::doesFileExist(const fs::path & _path, bool bRelativeToData){
1130+
auto path = _path;
1131+
if (path.empty()) {
1132+
return false;
1133+
}
11311134
if(bRelativeToData){
1132-
tmp.open(_fPath,ofFile::Reference);
1133-
}else{
1134-
tmp.openFromCWD(_fPath,ofFile::Reference);
1135+
path = ofToDataPath(path);
11351136
}
1136-
return !_fPath.empty() && tmp.exists();
1137+
return !path.empty() && of::filesystem::exists(path);
11371138
}
11381139

11391140
//------------------------------------------------------------------------------------------------------------

libs/openFrameworks/utils/ofFileUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ class ofFile : public std::fstream {
813813
/// are *not* in the data folder and want the direct path without relative
814814
/// "../../"
815815
/// \returns true if a file or directory exists
816-
static bool doesFileExist(const of::filesystem::path & fPath, bool bRelativeToData = true);
816+
static bool doesFileExist(const of::filesystem::path & _path, bool bRelativeToData = true);
817817

818818
/// Remove a file or directory at a given path.
819819
///

0 commit comments

Comments
 (0)