Return number of directories in a directories
Hi to all I have this code:
Code:
if( !dir.cd("IrisDatabase") )
{
qWarning("Cannot find the directory, creating it...");
dir.mkdir("IrisDatabase");
qDebug("Created");
}
else
qDebug("Directory ok");
uint num = dir.entryList().count();
qDebug() << num;
I would know why dir.entryList().count() returns 2 when the "IrisDatabase" directory is empty instead of 0.
I would list the number of directories contained on IrisDatabase
Where my code is wrong?
Re: Return number of directories in a directories
Nothing is wrong with your code, but instead of asking you just should have a look on what is returned. I bet it is "." and ".." since you are on linux. And they are in you directory even if you just have created it.
Moving to newbie. At least this thread...
Re: Return number of directories in a directories
Three clues:
1) Above post
2) Filters
3) QDir::NoDotAndDotDot
Re: Return number of directories in a directories
Thank you very much to all
Re: Return number of directories in a directories
Lykurg I'm not and Linux.
I'm under windows
Re: Return number of directories in a directories
Quote:
Originally Posted by
Lykurg
Nothing is wrong with your code, but instead of asking you just should have a look on what is returned. I bet it is "." and ".." since you are on linux. And they are in you directory even if you just have created it.
Moving to newbie. At least this thread...
Now I created a directory inside 'C:/IrisDatabase' directory named '1' so now I have this directory structure: 'C:/IrisDatabase/1'.
So I would know why this code:
Code:
QString path
= dir.
path();
// returns C:/IrisDatabase/1 dir.cdUp();
uint users = dir.count(); // returns 0 instead of 1
returns 0 instead of 1 ( in C:/IrisDatabase there is an empty directory named 1 ) and the dir.count() should returns 1
Re: Return number of directories in a directories
Has it occured to you to try printing out the contents of QDir.entryList() to see exactly what's being counted?
Please read the documentation of the code you're trying to use before using it. Pay particular attention, in this case, to the fact that you can set filters on QDir that affect what types of files are reported.
You do realize that QDir.count() doesn't return the number of directories alone, right?
Re: Return number of directories in a directories [SOLVED]]