#includeint main() { QFileInfoList fileList = QDir("/path/to/dir").entryInfoList(QDir::Files); foreach(QFileInfo file, fileList) { qDebug() << file.fileName(); } return 0; }
#includeThis code lists the files in "/path/to/dir" (including hidden files, but excluding symbolic links), and prints the size of each file to the console along with its name. It also calculates the total size of all the files and prints that to the console as well. Package/library: Qtint main() { QFileInfoList fileList = QDir("/path/to/dir").entryInfoList(QDir::Files | QDir::Hidden | QDir::NoSymLinks); qint64 totalSize = 0; foreach (QFileInfo file, fileList) { totalSize += file.size(); qDebug() << file.fileName() << file.size(); } qDebug() << "Total size:" << totalSize; return 0; }