2010-08-19 83 views

回答

0

顯然不是。但我發現這個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; 
} 
+0

Thans爲你的答案,但我不明白這一點,你能告訴我關於它。非常感謝 – john 2010-08-19 11:18:50

+0

什麼是fKB值? – john 2010-08-19 11:20:07