QT read all Files under folder (Super Simple method, do not need qdiriterator)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.