Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if directory is empty

Tags:

qt

qt4

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 ..?

like image 716
highlander141 Avatar asked May 03 '13 04:05

highlander141


People also ask

How do I check if a directory is empty in C++?

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.


1 Answers

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!!!");
}
like image 179
highlander141 Avatar answered Sep 17 '22 13:09

highlander141