我的代码非常简单:
void DirManagement::listFiles(QDir dir)
{
QFileInfoList list = dir.entryInfoList(QDir::NoFilter, QDir::NoSort);
for (int i = 0; i < list.size(); ++i)
{
QFileInfo fInfo = list.at(i);
QString fPath = fInfo.absoluteFilePath();
qDebug() << "# " << i << fPath; }
}问题是,如果我的目录路径是:"/home/adasi/Desktop/GCUFolder“,结果是:
# 0 "/home/Alya/Desktop/MCUFolder"
# 1 "/home/Alya/Desktop"
# 2 "/home/Alya/Desktop/MCUFolder/32Mon Oct 24 2011"
# 3 "/home/Alya/Desktop/MCUFolder/32Sun Oct 23 2011"然而,我期望的只是给定目录下的内容:
# 0 "/home/Alya/Desktop/MCUFolder/32Mon Oct 24 2011"
# 1 "/home/Alya/Desktop/MCUFolder/32Sun Oct 23 2011"我尝试了大部分的qt过滤器。没有起作用。
发布于 2012-04-25 02:09:42
就像Mat说的那样,添加更多的信息,指定你想要列出的内容,如下所示:
myQdirObject.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort);发布于 2011-10-24 16:10:33
使用QDir::NoDotAndDotDot筛选器,这将从搜索中删除目录本身及其父目录。
发布于 2011-10-24 20:27:19
应该使用QDir::NoDot | QDir::NoDotDot筛选器调用entryInfoList:
QFileInfoList list = dir.entryInfoList(QDir::NoDot | QDir::NoDotDot, QDir::NoSort);有关更多过滤器,请查看corresponding Qt Documentation。
https://stackoverflow.com/questions/7872155
复制相似问题