Windows API (与磁盘信息相关)

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

GetDriveType:用于判断驱动类型


UINT WINAPI GetDriveType(
  _In_opt_ LPCTSTR lpRootPathName
);



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

以下内容摘录自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, 

&sectorsPerCluster,

&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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值