Previously, read folders were written in standard C + +.
Now it's quite simple to rewrite the code with QT and see how QT is implemented.
Mainly used in the Qdir, detailed documents can be seen here
Lists all the files in the current directory (excluding symbolic links), sorted by size, smallest first:
?
| 0102030405060708091011121314151617181920 |
#include #include int main (int argc, char *argv[]) { qcoreapplication App (argc, argv); qdir Dir; dir.setfilter (QDir::Files | Qdir::hidden | Qdir::nosymlinks); dir.setsorting (Qdir::size | qdir::reversed); qfileinfolist list = Dir.entryinfolist (); std::cout << " Bytes Filename" << std::endl; for (int i = 0; i < list.size (); ++i) { qfileinfo fileInfo = list.at (i); std::cout << qprintable (QString ("%1%2"). Arg (Fileinfo.size (), ten) &nBsp; .arg ( Fileinfo.filename ()) std::cout << std::endl; } return 0;} |
The above code lists only the files in the current directory and does not recursively enter the subdirectory traversal.
Recursively traverse the subdirectories as follows:
?
| 010203040506070809101112131415< /td> |
qfileinfolist getfilelist (QString path) { qdir dir (path); & Nbsp; qfileinfolist file_list = dir.entryinfolist (Qdir::files | Qdir::hidden | qdir::nosymlinks); qfileinfolist folder_list = Dir.entryinfolist (QDir::D IRS | QDIR::NODOTANDDOTDOT); for (int i = 0; I! = Folder_list.size (); i++) { qstring name = folder_list.at (i). AbsoluteFilePath (); qfileinfolist child_file_list = GetFileList (name); file_list.append (child_file_list); } return file_list;} |
As for, after the Web page processing, you need to generate the corresponding output directory according to the input directory, you can use the Mkpath in Qdir
Http://blog.chinaunix.net/uid-25749806-id-315904.html
QT read all Files under folder (Super Simple method, do not need qdiriterator)