Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用C从Windows获取可用磁盘空间?_C_Windows - Fatal编程技术网

如何使用C从Windows获取可用磁盘空间?

如何使用C从Windows获取可用磁盘空间?,c,windows,C,Windows,我有一个磁盘被分割成多个分区。我想获得每个分区上的可用空间,以确定文件的最佳放置位置 我怎样才能用C来做这个 我一直在尝试使用以下代码: __int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes; DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters; test = GetDiskFreeSpaceEx(

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

我怎样才能用C来做这个

我一直在尝试使用以下代码:

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

test = GetDiskFreeSpaceEx(
        pszDrive,
        (PULARGE_INTEGER)&lpFreeBytesAvailable,
        (PULARGE_INTEGER)&lpTotalNumberOfBytes,
        (PULARGE_INTEGER)&lpTotalNumberOfFreeBytes
        );
但结果并不正确

有什么想法吗


谢谢

这对我来说很好:

 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));
         }
   }

实际上,这是要调用的正确函数。结果有什么问题?你有没有定义和初始化PSZDRIVER?考虑生成一个小的可编译程序来显示错误的行为。我从来没有使用过Windows。我用linux回答了你