I'm trying to check if a directory is empty.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QDir Dir("/home/highlander/Desktop/dir");
if(Dir.count() == 0)
{
QMessageBox::information(this,"Directory is empty","Empty!!!");
}
}
Whats the right way to check it, excluding .
and ..
?
Call IsEmpty to check whether a given directory is empty. An empty directory is considered to have no files or other directories in it. IsEmpty returns true if the directory is empty; false otherwise.
Well, I got the way to do it :)
if(QDir("/home/highlander/Desktop/dir").entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count() == 0)
{
QMessageBox::information(this,"Directory is empty","Empty!!!");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With