Something like this:
// 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;
}
// 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
QStringList excludedEntryList( const QString & path, const QStringList & excludedExts, QDir::Filters filters )
{
QStringList filteredEntries;
QDir dir( path );
QFileInfoList unfilteredInfos = dir.entryInfoList( filters );
for ( QFileInfo info : unfilteredInfos )
{
QString ext = info.suffix();
if ( !excludedExts.contains( ext ) && !excludedExts.contains( "." + ext ) )
filteredEntries.push_back( info.fullPath() );
}
return filteredEntries;
}
To copy to clipboard, switch view to plain text mode
Bookmarks