遍历指定文件夹的目录?Qt&c ++

sam*_*ode 3 c++ directory qt

我有一个包含以下结构的目录.

Name-
   -Year1
      -Month1
        -Day1
          -file1
        -..
      -...
   -Year2
      -Month1
      -...
   -...
Run Code Online (Sandbox Code Playgroud)

现在我有2个日期2009-01-02和2010-02-03.

我想问一下是否有人知道如何列出给定时间内文件夹中的所有文件,而不构建一个巨大的if-else结构.如果可能,没有任何其他框架而不是Qt.

任何帮助将不胜感激!

Ant*_*ony 8

看看QDir :: entryList(),它将列出文件夹中的所有文件.您可以像这样构造目录路径:

QString path = QDir::currentPath() + "/" +
               QString::fromNumber(year) + "/" +
               QString::fromNumber(month) + "/" +
               QString::fromNumber(day);
Run Code Online (Sandbox Code Playgroud)

然后呢

QDir dir(path);
QStringList files = dir.entryList();
Run Code Online (Sandbox Code Playgroud)

您可以对其他日期执行相同操作,然后组合两个QStringLists.