qt 查询指定目录下文件夹
时间: 2024-09-07 12:04:40 浏览: 83
在Qt中,你可以使用QDir类来查询指定目录下的文件和子目录。QDir是一个用于处理目录路径、文件名以及其他目录信息的工具。下面是如何使用它来查找特定目录下的内容:
```cpp
#include <QDir>
#include <QDebug>
void listFilesInDirectory(const QString &directoryPath) {
QDir dir(directoryPath);
if (!dir.exists()) {
qDebug() << "Directory does not exist.";
return;
}
QStringList files = dir.entryList(QDir::Files | QDir::Dirs); // 获取文件和子目录列表
for (QString filePath : files) {
qDebug() << "File: " << dir.filePath(filePath); // 输出完整路径
if (dir.isDir(filePath)) { // 判断是否为子目录
qDebug() << "Directory: " << filePath;
} else {
qDebug() << "Regular file: " << filePath;
}
}
}
// 调用函数并传入你要查询的目录路径
listFilesInDirectory("/path/to/your/directory");
```
阅读全文
相关推荐
















