1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include <QtGui> #include <iostream> #include <string>
qlonglong imageSpaceCompute(const QString &path) { QDir dir(path); qlonglong size = 0; QStringList filters; foreach(QByteArray format,QImageReader::supportedImageFormats()) filters += "*." + format; foreach(QString file, dir.entryList(filters,QDir::Files)) size += QFileInfo(dir,file).size(); foreach (QString subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) size += imageSpaceCompute(path + QDir::separator() + subDir); return size; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString path = QDir::currentPath(); std::cout << "Space used by imaged in" << qPrintable(path) << " and its subdirectories is " << (imageSpaceCompute(path) / 1024) << " KB" << std::endl; return 0; }
|