You need to add QDir::Dirs or QDir::AllDirs if you want dir.entryInfoList() to return directories as well as files.
Did you look at the documentation for QString to see what the QString::arg() method does?
Your example code seems very confusing to me. QDir::entryInfoList is used to return a QFileInfoList, which is a list containing a QFileInfo for every file and/or directory matched by the filters you set. A basic example of what I *think* you are trying to accomplish is:
{
if (!dir.exists())
{
qDebug("Directory does not exist: %s", qPrintable(path));
return;
}
dir.setNameFilers({"*.*"});
dir.
setSorting(QDir::Size |
QDir::Reversed);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.count(); i++)
{
if (fi.isDir())
{
process_dir(fi.absolutePath()); // if this QFileInfo is a directory, descend into the directory recursively to traverse all files/directories
}
else if (fi.isFile())
{
// if you get here, the QFileInfo is for a regular file, so do whatever processing you need to do for a file
}
}
return;
}
void process_dir(QString path)
{
QDir dir(path);
if (!dir.exists())
{
qDebug("Directory does not exist: %s", qPrintable(path));
return;
}
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::AllDirs);
dir.setNameFilers({"*.*"});
dir.setSorting(QDir::Size | QDir::Reversed);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.count(); i++)
{
QFileInfo fi = list.at(i);
if (fi.isDir())
{
process_dir(fi.absolutePath()); // if this QFileInfo is a directory, descend into the directory recursively to traverse all files/directories
}
else if (fi.isFile())
{
// if you get here, the QFileInfo is for a regular file, so do whatever processing you need to do for a file
}
}
return;
}
To copy to clipboard, switch view to plain text mode
When you first call the process_dir method above, pass it the root of the file system you want to process (i.e. "C:/" or whatever).
Hope that helps.
Bookmarks