Answer the question
In order to leave comments, you need to log in
How to get files from folders and subfolders?
I am trying to get a list of all files in a folder and subfolders. I try like this:
QList <QString> files;
void SearchFiles::scanDir(QDir dir){
if(!dir.exists()){
isFind = false;
return;
}
QFileInfoList listDir = dir.entryInfoList();
QFileInfo file;
foreach(QFileInfo finfo, listDir){
if(finfo.fileName() != "." || finfo.fileName() != ".."){
file.setFile(finfo.fileName());
if(file.isDir())
scanDir(file.absoluteDir());
else
files.push_back(file.absoluteFilePath());
}
}
}
Answer the question
In order to leave comments, you need to log in
It turned out to be easier than I thought:
QList <QString> files;
void SearchFiles::scanDir(QDir dir){
if(!dir.exists()){
isFind = false;
return;
}
QDirIterator it(dir, QDirIterator::Subdirectories);
QFileInfo finfo;
while (it.hasNext()) {
info.setFile(it.next());
if(finfo.fileName() != "." || finfo.fileName() != ".."){
files.push_back(finfo.absoluteFilePath());
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question