FileSearchPath::findChildFiles depth

A small feature request on FileSearchPath::findChildFiles recursivly. It would be cool to have a search depth limit option for findChildFiles just in case users set search directory like C:.

I am not very sure if it’s possible, but a optional for setting the maximum files required could come in handy.

Surely the smart thing to do would be to ask the user if they really mean "c:", and if so, search the whole thing?

Just use a DirectoryIterator and stop asking it for files when you’ve got enough.

I really don’t like either of these ideas - it feels wrong to put artificial limits on a file search, either in terms of depth or file count. If you’re searching for files, then presumably you don’t know what files are there, so how can you know what the limits are before you’ve searched?

I’m exploring searching for a file starting from C:\ and i’m wondering if there is a way to perform the recursive search on a separate thread, so it doesn’t appear that my app has frozen.

calling

File f("/"); 
FileSearchPath path(f.getFullPathName() ); 
Array<File> resultFiles;
path.findChildFiles(resultFiles, TypeOfFileToFind::findFiles, true, "someName");

takes a really long time, as it is scanning the ENTIRE drive.

i’m not sure if running it on its own thread would work either, as there really isn’t a place to pause execution, is there? Perhaps i’m mistaken about how threads work internally.

Check out the DirectoryContentsList class which uses a separate Thread for searching

Rail

gotcha. Seems handy, but it doesn’t do recursive searching:

void DirectoryContentsList::refresh()
{
    clear();

    if (root.isDirectory())
    {
        fileFindHandle = new DirectoryIterator (root, false, "*", fileTypeFlags);
        shouldStop = false;
        thread.addTimeSliceClient (this);
    }
} 

I need to do recursive searching, so that ‘false’ in the DirectoryIterator constructor needs to be true… any ideas?

Just use your own thread, with a DirectoryIterator. You can stop iterating any time you like.

I was suggesting you check out the class to see how it’s implemented in JUCE to see how you can make your own class.

Rail

1 Like