Very slow file listing with Visual Studio

I am trying to reuse some code of an OF project done with CodeBlocks in Windows in a new VS project, and I’ve notice that listing the files in a directory takes much more time.

For example the code:

ofDirectory fileList;
fileList.listDir("mydir/");

Blocks the application for more than 30 seconds, while the same code in the same machine compiled with CodeBlocks takes a fraction of a second.

I’ve seen this time is dependent on the number of files in the directory.

I suppose that it has to do with how mingw and MS compiler handle POCO file handling functions. May it be possible to configure VS somehow to improve this behavior or perhaps it is necessary to use native Windows functions to manage better files?

Best regards.

What version of OF are you using? 30 seconds seems extremely high. Even with folders that have 100’s of image files in it populating an ofDirectory for me takes less than a second. How many items are in the folder?

I’m using of 0.8.4.

There are about 1000 files in the folder.

The point is that these 1000 files are listed very quickly with of 0.8.4 with CodeBlocks in Windows.

Can you test to see if its actually the listDir or the open() that is taking the longest
try:

fileList.open("mydir/");
fileList.listDir();

and compare it to the code you posted above

Maybe try to build your application in release mode ? In my experience file access is super slow in debug with VS probably for some memory checking and such…

Thanks DomAmato and silverbahamut.

The code:

float t0 = ofGetElapsedTimef();
fileList.open("mydir/");
cout << "open time " << ofGetElapsedTimef()-t0 << "\n";
t0 = ofGetElapsedTimef();
fileList.listDir();
cout << "list time " << ofGetElapsedTimef()-t0 << "\n";
cout << fileList.numFiles() << "\n";

Gives an “open time” of 0 seconds and a “list time” of 17 seconds for 1200 files.

As silverbahamut points it is related with some checking of the debug mode, in release mode I get an “open time” of 0 seconds and “list time” of 0.8 seconds for 1200 files.

I seems still a bit high to me (I am under a quite new PC with SSD disk) but much more reasonable.

Regards.