0
디렉터리의 재귀 적 검색에서 올바른 값을 반환하는 데 문제가 있습니다. 아래 코드는잘못된 값을 반환하는 디렉터리를 재귀 적으로 검색
#include <QCoreApplication>
#include <QDir>
#include <QString>
#include <QDebug>
static QString findDirectoryPathFromId(const QString &startPath, const QString &id)
{
QDir dir(startPath);
QFileInfoList list = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
QString path;
foreach(QFileInfo dinfo, list)
{
if (dinfo.fileName() == id)
{
qDebug() << "****************Found****************" << dinfo.filePath();
return dinfo.filePath();
}
else
{
findDirectoryPathFromId(dinfo.absoluteFilePath(), id);
}
}
return QString();
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QStringList args = app.arguments();
QString path = findDirectoryPathFromId("/home/project/dirtest", args.at(1));
qDebug() << "Return path" << path;
return 0;
}
입니다.이 함수는 "Found"디버그 문을 인쇄 할 때 디렉토리를 찾습니다. 반환 값은 null 문자열입니다.
아무도 내가 여기서 잘못하고있는 것을 설명 할 수 있습니까?
감사합니다.