1

我有 1 个磁盘被分成多个分区。我想获得每个分区上的可用空间,以确定最好的文件放置位置。

我怎样才能在 C 中做到这一点?

我一直在尝试使用此代码:

__int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;

test = GetDiskFreeSpaceEx(
        pszDrive,
        (PULARGE_INTEGER)&lpFreeBytesAvailable,
        (PULARGE_INTEGER)&lpTotalNumberOfBytes,
        (PULARGE_INTEGER)&lpTotalNumberOfFreeBytes
        );

但结果不正确。

有任何想法吗 ?

谢谢

4

1 回答 1

4

这对我来说很好:

 void main (int argc, wchar_t **argv)
   {
      BOOL  fResult;
      unsigned __int64 i64FreeBytesToCaller,
                       i64TotalBytes,
                       i64FreeBytes;
         fResult = GetDiskFreeSpaceEx (L"C:",
                                 (PULARGE_INTEGER)&i64FreeBytesToCaller,
                                 (PULARGE_INTEGER)&i64TotalBytes,
                                 (PULARGE_INTEGER)&i64FreeBytes);
         if (fResult)
         {
            printf ("\n\nGetDiskFreeSpaceEx reports\n\n");
            printf ("Available space to caller = %I64u MB\n",
                    i64FreeBytesToCaller / (1024*1024));
            printf ("Total space               = %I64u MB\n",
                    i64TotalBytes / (1024*1024));
            printf ("Free space on drive       = %I64u MB\n",
                    i64FreeBytes / (1024*1024));
         }
   }
于 2012-08-11T22:32:28.783 回答