[SOLVED] Read unknown .txt files in a folder?
-
wrote on 4 Dec 2012, 12:42 last edited by
let's say there are some unknown .txt files in a folder,
how can I read them without knowing the file names?
is that possible, I googled already quite alot, but couldnt find anything
€ so how can I request the file names? If I know them I can also read them.
-
wrote on 4 Dec 2012, 12:56 last edited by
If you know the filepath for the folder where the files are stored you can get the individual file in the directory using "QDir":http://qt-project.org/doc/qt-4.8/qdir.html . Have a look at the "examples":http://qt-project.org/doc/qt-4.8/qdir.html#examples , its pretty much selfexplanatory.
To open the files you can use "QFile":http://qt-project.org/doc/qt-4.8/qfile.html .
-
wrote on 4 Dec 2012, 13:21 last edited by
cool thx,
luckily there was an already nice sample code
this could be helpful for someone, nice
@ QFile file2("movie-list.txt");
file2.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out2(&file2);QDir dir("movies"); dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); dir.setSorting(QDir::Size | QDir::Reversed); QFileInfoList list = dir.entryInfoList(); out2 << " Bytes Filename" << endl; for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); out2 << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10) .arg(fileInfo.fileName())) << endl;
}@
1/3