请问高手,如何获取一个硬盘分区的大小:如"C:"区,以及分区的可用空间大小.解决即给分结贴.本人结贴率100%

解决方案 »

  1.   

    晕,查API也不查!msdn.microsoft.com
      

  2.   

    //delphi help里的,呵呵
    var  S: string;
      AmtFree: Int64;
      Total:   Int64;
    begin
      AmtFree := DiskFree(0);
      Total := DiskSize(0);
      S := IntToStr(AmtFree div Total) + 'percent of the space on drive 0 is free: ' (AmtFree div 1024) + ' Kbytes free. ';
      Label1.Caption := S;
    end;
    --------------------------------------------------------------------
    var  S: string;
      AmtFree: Int64;
      Total:   Int64;
    begin
      AmtFree := DiskFree(0);
      Total := DiskSize(0);
      S := IntToStr(AmtFree div Total) + 'percent of the space on drive 0 is free: ' (AmtFree div 1024) + ' Kbytes free. ';
      Label1.Caption := S;
    end;
      

  3.   

    获得可用的驱动器列表
    var 
    i:integer;
    c:String;
    Dtype;Integer;
    DriveString:String;
    begin
    //从A到Z循环
    for i:=65 to 90 do
    begin
    //格式化一个字符串,用来表示根目录
    c:=chr(i)+':\';
    //调用GetDriveType()来返回一个整数值
    Dtype:=GetDriveType(PChar(C));
    //根据返回的驱动器类型来格式化一个字符串
    case Dtype of
    0:DriveString:=C+'不能确定驱动器类型';
    1:DriveString:=C+'根目录不存在';
    Drive_Removable:DriveString:=C+'驱动器可移动';
    Drive_fixed:DriveString:=C+'驱动器为远程驱动器';
    Drive_cdrom:DriveString:=C+'驱动器为CD-ROM';
    Drive_ramdisk:DriveString:=C+'驱动器为硬盘分区';
    end;
    if Dtype=Drive_ramdisk then
    Lbdrive.items.addobject(drivestring,pointer(i));
    end;
    end;
    //取得指定驱动器的信息
    var
    rootpath:string;//保存驱动器的根路径
    sectorspercluster:dword;//每簇的扇区数
    bytespersector:Dword;//每扇区的字节数
    numfreeclusters:dword;//可用簇数
    totalclusters:Dword;//总簇数
    drivebyte:byte;//驱动器字节值
    freespace:int64;//驱动器上和可用空间
    totalspace:int64;//磁盘总容量
    begin
    with lbdrives do
    begin
    {将驱动器号的ASCII码减去64,就得到驱动器编号}
    drivebyte:integer(items.objects[itemindex])-64
    {创建根路径}
    rootpath:=chr(integer(items.objects[itemindex]))+':\';
    {通过调用GetDiskFreeSpace()函数来获得驱动器的信息}
    if GetDiskFreepace(PChar(RootPath),sectorsPerCluster,BytesPerSector,NumFreeclusters,Totalclusters) then
    begin
    lblsectpercluster.caption:=sectorspercluster;
    lblbytespersector.caption:=bytespersector;
    lblnumfreeclust.caption:=numfreeclusters;
    lbltotalclusters.caption:totalclusters;
    //获得可用的磁盘空间
    freespace:=diskfree(drivebyte);
    totalspace:=disksize(drivebyte);
    //计算驱动器的总容量,
    lblfreespace.caption:=freespace;
    lbltotaldiskspace.caption:=totalspace
    end;
    end; 
    呵呵,长了点
      

  4.   

    //M$ 脚本help里的,是activex,可通过delphi的comobj调用,呵呵。function ShowDriveInfo1(drvPath)
    {
      var fso, drv, s ="";
      fso = new ActiveXObject("Scripting.FileSystemObject");
      drv = fso.GetDrive(fso.GetDriveName(drvPath));
      s += "Drive " + drvPath.toUpperCase()+ " - ";
      s += drv.VolumeName + "<br>";
      s += "Total Space: " + drv.TotalSize / 1024;
      s += " Kb" + "<br>"; 
      s += "Free Space: " + drv.FreeSpace / 1024;
      s += " Kb" + "<br>";
      Response.Write(s);
    }