How to exclude a specific file extension from QDir::entryList
Hi community,
I know how to specify the file extensions that I would like to be considered when I call the QDir::entryList method:
In this case the files having extensions ext1 and ext2 only are considered. But how to exclude a specific extension?
For example I would like to considere ALL the extensions except a specific one ( in my case *.conf )
Thx
Re: How to exclude a specific file extension from QDir::entryList
Hi, I'm not sure if entryList() can do that. But you can simply get all files, then iterate over the stringlist and remove the matching files afterwards.
Ginsengelf
Re: How to exclude a specific file extension from QDir::entryList
Something like this:
Code:
// Note that since QFileInfo::suffix() returns the extension -without- a leading ".", the code allows the
// excluded extensions list to contain either "ext" or ".ext" and will check for both.
//
// This will also include files with no extensions, so if that is not desired, check the suffix for isEmpty()
// and discard them too.
//
// Usage:
//
// QStringList noBinaryList = excludedEntryList( path, QStringList() << ".exe" << "dll", QDir::Files | QDir::NoDot | QDir::NoDotAndDotDot );
// Untested code! Might contain bugs
{
QFileInfoList unfilteredInfos = dir.entryInfoList( filters );
{
if ( !excludedExts.contains( ext ) && !excludedExts.contains( "." + ext ) )
filteredEntries.push_back( info.fullPath() );
}
return filteredEntries;
}