Windows API (与磁盘信息相关)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

GetDriveType:用于判断驱动类型


UINT WINAPI GetDriveType(
  _In_opt_ LPCTSTR lpRootPathName
);

Windows API (与磁盘信息相关)_第1张图片


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

以下内容摘录自MSDN && http://zhidao.baidu.com/question/64422451.html


GetVolumeInformation function

GetVolumeInformation(
lpRootPathName: PChar; {根目录名}
lpVolumeNameBuffer: PChar; {接收卷名的缓存}
nVolumeNameSize: DWORD; {指定缓存大小}
lpVolumeSerialNumber: PDWORD;{卷序列号指针}
var lpMaximumComponentLength: DWORD; {maximum file component name}
var lpFileSystemFlags: DWORD; {文件系统格式标记}
lpFileSystemNameBuffer: PChar;{文件系统格式缓存}
nFileSystemNameSize: DWORD {文件系统名称}
): BOOL;  
    
下面为示例
procedure TForm1.Button1Click(Sender: TObject);
var
  RootPath: array[0..20] of Char;     // holds the root directory name
  VolName: array[0..255] of Char;     // holds the volume name
  SerialNumber: DWORD;                // holds the serial number
  MaxCLength: DWORD;                  // holds the maximum file component length
  FileSysFlag: DWORD;                 // holds file system flags

  FileSysName: array[0..255] of Char; // holds the name of the file system
begin
  {indicate information is to be retrieved from the C drive}
  RootPath := 'C:\';

  {retrieve the volume information}
  GetVolumeInformation(RootPath, VolName, 255, @SerialNumber, MaxCLength,
     FileSysFlag, FileSysName, 255);

  {display the information}
  Panel2.Caption := VolName;
  Panel3.Caption := IntToHex(SerialNumber,8);

  Panel4.Caption := FileSysName;
end;

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

GetDiskFreeSpace 

BOOL WINAPI GetDiskFreeSpace(
  _In_  LPCTSTR lpRootPathName,            //传入参数
  _Out_ LPDWORD lpSectorsPerCluster, 
  _Out_ LPDWORD lpBytesPerSector,
  _Out_ LPDWORD lpNumberOfFreeClusters,
  _Out_ LPDWORD lpTotalNumberOfClusters
);

该函数有4个输出值 , 对应分别是

每簇的扇区数,

每扇区的字节数,

簇剩余,

簇总计,


注意调用该函数的时候,在传参过程中,需要传入该参数的引用

EP:

GetDiskFreeSpace

(

lpRootPathName, 

§orsPerCluster,

&bytesPerSector,

&numberOfFreeClusters,

&totalNumberOfClusters

);


MSDN的中关于GetDiskFreeSpace的使用限制:

GetDiskFreeSpace cannot report volume sizes that are greater than 2 GB. 

To ensure that your application works with large capacity hard drives, use the GetDiskFreeSpaceEx function.\


//

GetDiskFreeSpaceEx 

     Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread.


BOOL WINAPI GetDiskFreeSpaceEx(
  _In_opt_  LPCTSTR         lpDirectoryName,
  _Out_opt_ PULARGE_INTEGER lpFreeBytesAvailable,
  _Out_opt_ PULARGE_INTEGER lpTotalNumberOfBytes,
  _Out_opt_ PULARGE_INTEGER lpTotalNumberOfFreeBytes
);


Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero (0). To get extended error information, call GetLastError.


你可能感兴趣的:(Windows API (与磁盘信息相关))