isDirectorySuitable, DirectoryIterator and multiple files

Guys, I’m doing a TreeView that lists more than one file type. EG: WAV, SFZ, FXP, FXB, … and I added an option to check if the folders have the actual files found.

I’m using the isDirectorySuitable call. So I create a DirectoryIterator call and check if all sub folders contains any file with those extensions. The problem is that DirectoryIterator only handles one extension at a time. I tried to figure out how it works, but I rather ask here before I start re-inventing the wheel. :oops:

Thanks, Wk

I’d suggest just scanning for all files, and do your own quick check on the files that it returns.

Of course, I was wondering about that too. :oops:

Ok, I will get something done and post it over when ready. 8)

Wk

Here’s the solution:

[code]//-----------------------------------------------------------------------------------------------------------
class JUCE_API myFilter : public WildcardFileFilter
{
public:
myFilter (const String& wildcardPatterns,
const String& description);

bool isDirectorySuitable (const File& file) const;
bool scanFolder;
bool stopScan;

StringArray wildcards;

};[/code]

[code]//-----------------------------------------------------------------------------------------------------------
myFilter::myFilter (const String& wildcardPatterns,
const String& description)
: WildcardFileFilter (wildcardPatterns, description)
{
scanFolder = false;
stopScan = false;

wildcards.addTokens (wildcardPatterns.toLowerCase(), T(";,"), T("\"'"));
wildcards.trim();
wildcards.removeEmptyStrings();
for (int i = wildcards.size(); --i >= 0;)
{
    if (wildcards[i] == T("*.*")) wildcards.set (i, T("*"));
}

}

//-----------------------------------------------------------------------------------------------------------
bool myFilter::isDirectorySuitable (const File& file) const
{
if (scanFolder)
{
if (stopScan) return false;

	bool Found = false;

	if (!stopScan) 
	{
		DirectoryIterator iter (file, true);
		while(iter.next())
		{
			if (stopScan) break;

			String filename = iter.getFile().getLinkedTarget().getFileName();
			for (int i = wildcards.size(); --i >= 0;)
			{
				if (filename.matchesWildcard(wildcards[i], true))
				{
					Found = true;
					break;
				}
			}

			if (Found) break;
		}
	}

	return Found;
}

return true;

}[/code]

Now, when scanFolder is True, it will check if the folder and all sub-folders have ANY of the wildcard files. You can also set stopScan to True if the user has clicked a STOP button. (very handy)

Hope this is useful to somebody else. 8)

Best Regards, WilliamK