Search code examples
macoswxwidgets

wxFileExists returns false in Mac


I am using wxWidgets in Mac with C++ (obviously) and Xcode.

This line returns false, when it should be true.

` if(!wxFileExists(filePicker->GetPath())
{
 wxMessageDialog(this, "error").ShowModal();
 return;
} `

where filePicker is a wxFilePickerCtrl. It's value is : filepath std::__1::string "/Users/swtsvn/Main/Proj1/Mac/binaries/osx/Debug/wxSampleApp.app"

The path has upper case, and no spaces. The File is located in that path, since I picked that file path using file picker wxWidget tool.

I searched for a reason wxFileExists might return false on Mac but not on Windows, but could not find one in Google.

If anyone knows the answer, kindly let me know.


Solution

  • According to the docs, wxFileExists():

    Returns true if the file exists and is a plain file.

    So, it returns false for directories. Mac app bundles, such as your wxSampleApp.app, are directories. It is the intentional behavior of the function that it return false in this case.

    You could presumably use wxFileExists(path) || wxDirExists(path) instead, although that will be somewhat inefficient.