Know if a directory is empty or not in QT

#Include <QDir> #Include <QFileInfo> #Include <QDebug> bool isEmptyFolder(QString path){ bool exist; QDir dir(path); QFileInfoList files = dir.entryInfoList(QDir::NoDotAndDotDot); foreach (QFileInfo item, files){ if(item.exists()){ //qDebug() << item.absoluteFilePath(); exist = true; } } if (exist){ return false; }else{ return true; } }
A simply bool function to know if a directory is empty or not in QT framework of C++.

2 Responses

omg, it's the worst code I've ever seen...
it can be simply written like:

bool isEmptyFolder(QString path) {
return QDir(path).entryList(QDir::NoDotAndDotDot|QDir::AllEntries).count() == 0;
}
omg, it's the worst code I've ever seen...
it can be simply written like:

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.