doesDirectoryExist on a distant folder crash the dirListExample

Hi there,

Below is the setup of my application (derived from dirListExemple)

//--------------------------------------------------------------
void ofApp::setup(){
if (dir.doesDirectoryExist("//New-host/bigBacks")) {
	dir.listDir("//New-host/bigBacks");
	//dir.sort(); // in linux the file system doesn't return file lists ordered in alphabetical order

	//allocate the vector to have as many ofImages as files
	if( dir.size() ){
		images.assign(dir.size(), ofImage());
	}

	// you can now iterate through the files and load them into the ofImage vector
	for(int i = 0; i < (int)dir.size(); i++){
		images[i].loadImage(dir.getPath(i));
	}
}
currentImage = 0;

ofBackground(ofColor::white);
}

This is the setup of this example. Actually I’ve only add the doesDirectoryExist function with a path of a share folder on an other computer.
If I test it with a folder that does not exists it raises an unexpected poco exception.
With a path on my computer (that does not exists too) it doesn’t raises a poco exception but an error …
With a valid path on a distant computer it works (of course).

I have to change the doesDirectoryExist function to catch this exception.

//------------------------------------------------------------------------------------------------------------
bool ofDirectory::doesDirectoryExist(string dirPath, bool bRelativeToData){
try{
	if(bRelativeToData){
		dirPath = ofToDataPath(dirPath);
	}
	File file(dirPath);
	return file.exists();
}
catch(Poco::Exception & except){
	ofLogError("ofDirectory") << "doesDirectoryExist(): couldn't find directory \"" << dirPath << "\": " << except.displayText();
	return false;
}

}

Computer : windows 8.1, VS2012, OF 0.8.4

Cheers

Hy Community,

I have the same problem with windows 10, vs2015, OF093

I try to change the code of the doesDirectoryExist function but Poco::Exception does not exist anymore. Is there any other to way to call an exception in OF ?

it should be std::exception now

Thanks Arturo !

Then my modified doesDirectoryExist function is like that.

Is it a good idea to have this try/catch exception in a future release of OF ?

//------------------------------------------------------------------------------------------------------------
bool ofDirectory::doesDirectoryExist(const std::string& _dirPath, bool bRelativeToData){
std::string dirPath = _dirPath;
try {
	if (bRelativeToData) {
		dirPath = ofToDataPath(dirPath);
	}
	return std::filesystem::exists(dirPath) && std::filesystem::is_directory(dirPath);
}
catch (std::exception & except) {
	ofLogError("ofDirectory") << "doesDirectoryExist(): couldn't find directory \"" << dirPath << "\": " << except.what()<<endl;
	return false;
}
}

yeah totally, if you want to send a pull request?