Basically, I do this:
Check C:\\Windows directory properties: Size: 22.6 GB (24,281,251,244 bytes), Files: 154,028 Files
Then, using the following code, I try to achieve same numbers:
inline uint64_t file_size(std::string fname)
{
std::ifstream ifs(fname, std::ifstream::ate | std::ifstream::binary);
return ifs.tellg();
}
...
QDirIterator it (path_, QDir::Files | QDir::Hidden | QDir::System , QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
while (it.hasNext())
{
QFileInfo info(it.next());
// QFileInfo::size is messed up for *.lnk files, had to improvise
uint64_t size;
if (info.isSymLink())
size = file_size(info.absoluteFilePath().toStdString());
else
size = info.size();
current_sz_desc_.full_size_ += size;
current_sz_desc_.file_count_ ++;
}
What I get: 21,788,122,091 bytes, Files: 148823
It works for all user-created directories, but somehow fails for system ones (Program Files, Windows, etc). What is wrong?
Hi im assuming here by the code you shared that you have enough experience to see what i did and be able to reproduce the concept for your own idea(i didnt put full code just what it need to be see. http://doc.qt.io/qt-5/qstorageinfo.html#bytesTotal | http://doc.qt.io/archives/qt-4.8/qdir.html (keep it simple as you can , the complexity of your script should be equal to the complexity of the task asked) this script will look any directory(including program file system) but not the hided ones
int count = 0 ;
QString Root ;
void MyFunction()
{
QStorageInfo storage = QStorageInfo::root() ;
qDebug() << storage.rootPath();
/*bytes will be only once /1000 not /1000/1000*/
qDebug() << "size:" << storage.bytesTotal()/1000/1000 << "MB";
qDebug() << "name:" << storage.name();
qDebug() << "fileSystemType:" << storage.fileSystemType();
qDebug() << "availableSize:" << storage.bytesAvailable()/1000/1000 << "MB";
Root = storage.rootPath() ;
QDirIterator Load_Path(Root, QDirIterator::Subdirectories) ;
do
{
count = count + 1 ;
qDebug() << count ;
}while(Load_Path.hasNext()) ;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.