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