"QT5 Development and examples" 26, get the file size and directory path

Source: Internet
Author: User

To tell the truth, I was to mix a persistent label = =, who told me that the new year is not how to write!!!!


/*** Book: "QT5 Development and examples" * function: Get the file size and directory path * file: main.cpp* time: February 3, 2015 21:18:16* Author: cutter_point*/#include < qcoreapplication> #include <QStringList> #include <QDir> #include <qtdebug>//  According to the path given to get the file size and directory Qint64 du (const QString &path) {qdir dir (path);//This class can provide the directory of the file and the class tolerance qint64 size = 0;    Get all files and directories under File directory foreach (Qfileinfo fileInfo, Dir.entryinfolist (qdir::files)) {size + = Fileinfo.size (); Add up the size of all files}//Get all subdirectories under the size of the file//list of directories, do not list special entries, "."  and ".." foreach (QString subdir, Dir.entrylist (qdir::D irs|    QDIR::NODOTANDDOTDOT) {//path + current system separator + directory name size + = du (path + qdir::separator () + subdir);  Recursive invocation, traversing all directories, depth first} char unit = ' B ';    Qint64 cursize = size;  The size of this directory if (Cursize > 1024) {//The current size is larger than 1024 bytes, the above count is Fileinfo.size () cursize/= 1024 by byte size;   Except unit = ' K ';          KB if (Cursize > 1024) {//also large cursize/= 1024;   Unit = ' M '; MB if (Cursize > 1024) {              Cursize/= 1024;   Unit = ' G '; GB}//if}//if}//if qdebug () <<curSize<<unit<< "\ T" <<qprintable (PATH) &  lt;<endl; return size;}  int main (int argc, char *argv[]) {qcoreapplication A (argc, argv);  Qstringlist args = A.arguments ();  QString path;    if (Args.count () > 1) {path = args[1];    } else {path = Qdir::currentpath (); } qdebug () <<path<<endl;//path = "d:/qt/5.1.0-rel-static";//Path = "E:/DNF";//Path = "e:/League of Legends";//Path  = "f:/Podcasts video Tutorial";  Du (path); return a.exec ();}




"QT5 Development and examples" 26, get the file size and directory path

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.