【问题标题】:Check Disk fullness [duplicate]检查磁盘完整性[重复]
【发布时间】:2011-04-01 00:25:30
【问题描述】:

可能重复:
How to determine how much free space on a drive in Qt?

如何使用 Qt 使用 C++ 检查磁盘的完整性? 非常感谢

【问题讨论】:

标签: c++ qt disk


【解决方案1】:

显然不是。但我发现了这个here

#ifdef _WIN32
    #include <windows.h>
#else // linux stuff
    #include <sys/vfs.h>
    #include <sys/stat.h>
#endif // _WIN32

bool getFreeTotalSpace(const QString& sDirPath,double& fTotal, double& fFree)
{
#ifdef _WIN32

    QString sCurDir = QDir::current().absPath();
    QDir::setCurrent( sDirPath );

    ULARGE_INTEGER free,total;
    bool bRes = ::GetDiskFreeSpaceExA( 0 , &free , &total , NULL );
    if ( !bRes ) return false;

    QDir::setCurrent( sCurDir );

    fFree = static_cast<double>( static_cast<__int64>(free.QuadPart) ) / fKB;
    fTotal = static_cast<double>( static_cast<__int64>(total.QuadPart) ) / fKB;

#else //linux

    struct stat stst;
    struct statfs stfs;

    if ( ::stat(sDirPath.local8Bit(),&stst) == -1 ) return false;
    if ( ::statfs(sDirPath.local8Bit(),&stfs) == -1 ) return false;

    fFree = stfs.f_bavail * ( stst.st_blksize / fKB );
    fTotal = stfs.f_blocks * ( stst.st_blksize / fKB );

#endif // _WIN32

    return true;
}

【讨论】:

  • 感谢您的回答,但我无法理解这一点,您能告诉我。非常感谢
猜你喜欢
  • 2010-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-18
  • 1970-01-01
相关资源
最近更新 更多