I want to get all images filepath name in a directory

Hi, All.

I want to get all images filepath name in a directory.
and that diretory is got from draginfo of dragEvent.

My code is here:
void ofApp::dragEvent(ofDragInfo dragInfo){

if( dragInfo.files.size() > 0 ){
    img1.load(dragInfo.files[0]);
    img1.setImageType(OF_IMAGE_COLOR);
    
    ofDirectory dir(dragInfo.files[0]);
    dir.allowExt("png");
    dir.listDir();
    // all file
    for(int i = 0; i < dir.size(); i++){
        ofLog() << dir.getPath(i) << endl;
    }
}
ofSetWindowShape(img1.getWidth(), img1.getHeight());

}

But I met this error:
“[ error ] ofDirectory: listDir:() source directory does not exist:”

What’s wrong to me ?

Thanks.

Hi, are you dragging a file or a folder?
you coul do something like

for(int i = 0; i < dragInfo.files.size(); i++){
		ofFile fl(dragInfo.files[i]);
		if(fl.isFile()){
			cout << "File: ";
			//load the file
		}else if(fl.isDirectory()){
			cout << "Directory: ";
			//load the directory s files.
		}
		cout << f << ", ";
	}
1 Like

Hi, @roymacdonald

Thank you.

I’ll try that, and report.

from @bemoregt.