Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PythonUtils: more portable version of dirExists() #792

Merged
merged 1 commit into from
May 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 9 additions & 17 deletions Global/PythonUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

#include <cstdlib>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>

#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma warning (disable : 4996)
#else
#include <dirent.h>
#include <sys/stat.h>
#endif

#include "../Global/FStreamsSupport.h"
Expand All @@ -53,24 +54,15 @@ static bool fileExists(const std::string& path)

static bool dirExists(const std::string& path)
{
#ifdef _MSC_VER
char* pathCpy = strcpy(path.c_str());
strcat(path.c_str(), "\\*");
WIN32_FIND_DATA find_data;
HANDLE h = FindFirstFile(pathCpy, &find_data);
pathCpy[strlen(pathCpy) - 2] = '\0';
if (h == INVALID_HANDLE_VALUE) {
return false;
}
FindClose(h);
#else
DIR* d = opendir(path.c_str());
if (d == NULL) {
// https://stackoverflow.com/q/18100097
struct stat info;

if(stat(path.c_str(), &info ) != 0) {
return false;
} else if(info.st_mode & S_IFDIR) {
return true;
}
closedir(d);
#endif
return true;
return false;
}

void setupPythonEnv(const char* argv0Param)
Expand Down