ich möchte alle Dateien und Unterordner ab einem bestimmten Pfades in ein Textedit füllen, in der Art:
\Datei1.txt
\Datei2.txt
\Unterordner1\DateiU1.txt
\Unterordner1\UnterUnterordner1\DateiUU1.txt
\Unterordner1\UnterUnterordner1\DateiUU2.txt
Ich habe schon versucht mit QDir und QFileInfoList über ein eine Funktion zur Unterordnersuche und eine Funktion zur Dateisuche zu arbeiten, aber dies ist sehr mühsam. hat jemand eine effizientere idee oder gibt es etwas natives von Qt hierzu?
Code: Alles auswählen
QStringList MainWindow::getSubDirectories(QString path)
{//! get sub directoriy list of path entry
QStringList tmpList;
QDir Dir(path);
QFileInfoList filesList = Dir.entryInfoList();
//clear list
tmpList.clear();
//get all file names of current path
foreach(QFileInfo fileInfo, filesList)
{ //check if entry is a file
if(fileInfo.isDir()) {
//append in list with folder marks
tmpList.append(fileInfo.path());
}
}
return(tmpList);
}
QStringList MainWindow::getFileNames(QString path, QString folder)
{//! get file names in defined path and return it as list with prepended folder name
QStringList tmpList;
QDir Dir(path);
QFileInfoList filesList = Dir.entryInfoList();
//clear list
tmpList.clear();
//get all file names of current path
foreach(QFileInfo fileInfo, filesList)
{ //check if entry is a file
if(fileInfo.isFile()) {
//check if folder param was set
if (folder.size() < 1) { //append in list wothout folder marks
tmpList.append(fileInfo.fileName());
}
else { //append in list with folder marks
tmpList.append(folder + "\\" + fileInfo.fileName());
}
}
}
return(tmpList);
}