Use the API function to get disk space and disk types

xiaoxiao2021-03-06  39

procedure TForm1.Button1Click (Sender: TObject); var RootPath: string; Sed_Cluster, Bytes_Sec, Free_Clusters, Total_Clusters: DWord; begin Memo1.Clear; RootPath: = 'C: /'; if RootPath <> '' then begin GetDiskFreeSpace (PChar (RootPath), Sed_Cluster, Bytes_Sec, Free_Clusters, Total_Clusters); Memo1.Lines.Add ( 'C total disk space:' FloatToStrF (Sed_Cluster * Bytes_Sec * Total_Clusters / 1024/1024/1024, ffNumber, 8,2) 'G '); Memo1.Lines.Add (' C disk applicable space: ' floattostrf (sed_cluster * bytes_sec * free_clusters / 1024/1024/1024, ffnumber, 8, 2) ' g '); end; end; getDiskFreespace function 2GB of disk space than for the case, in this case, should use GetDiskFreeSpaceEx function, refer to the author of the following codes (the GetDriveType function reads disk type): procedure TForm1.Button1Click (Sender: TObject); var RootPath, DriveInfo: string; total_Space, Free_Available: int64; intDrvTypeID: integer; dblFree, dblTotal: double; begin Memo1.Clear; RootPath: = UpperCase (Copy (DriveComboBox1.Text, 1,1)); if RootPath <> '' then begin GetDiskFreeSpaceEx (PChar (RootPath ': / '), Free_available, total_space, nil); DriveInfo: = R Ootpath 'disk total space is'; DBLTOTAL: = Total_Space / 1024/1024/1024; if DBLTOTAL> = 1 Then DriveInfo: = DriveInfo FLOATTOSTRF (DBLTOTAL, FFNUMBER, 8, 2) ' GB. 'Else DriveInfo: = DriveInfo Floattostrf (DBLTOTAL * 1024, FFNUMBER, 8, 0) ' MB. '; Memo1.Lines.Add (DriveInfo); DriveInfo: = RootPath ' disc space available '; dblFree: = Free_Available / 1024/1024/1024; if dblFree> = 1 then DriveInfo: = DriveInfo FloatToStrF (dblFree, ffNumber 8, 2) 'GB.

转载请注明原文地址:https://www.9cbs.com/read-77778.html

New Post(0)