奕滔 發表於 2014-7-24 11:16:56

Delphi实现获取磁盘空间大小的方法

<p>本文所述Delphi实例用以获取指定的磁盘空间容量大小,检测磁盘大小,从combox中选择磁盘代号等功能。点击“检测驱动器”容量信息的按钮,就可以在下边显示出该磁盘的总空间大小以及要用容量的大小。读者可根据需求添加对应的Button与label控件。</p>
<p>主要程序代码如下所示:</p>
<div class="jb51code">
<pre class="brush:delphi;">
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
driver:pchar;
sec1, byt1, cl1, cl2:longword;
begin
driver:=pchar(edit1.text);//要显示的驱动器名
GetDiskFreeSpace(driver, sec1, byt1, cl1, cl2);
cl1 := cl1*sec1 * byt1;
cl2 := cl2*sec1 * byt1;
Label1.Caption:= '该驱动器总共容量' + Formatfloat('###,##0',cl2) + '字节';
Label2.Caption := '该驱动器可用容量' + Formatfloat('###,##0',cl1) + '字节';
end;
end.</pre>
</div>
                           
                            <div class="art_xg">
                              <b>您可能感兴趣的文章:</b><ul><li>Delphi实现窗口文字淡入淡出渐变效果的方法</li><li>delphi简单判断程序30秒没有键盘和鼠标动作示例</li><li>Delphi编程常用快捷键大全</li><li>Delphi实现限定软件使用时间的方法</li><li>Delphi实现图像文本旋转特效完整实例代码</li><li>Delphi实现图片滚动切换的完整实例代码</li><li>Delphi实现窗体感知鼠标滑过并自动隐藏与显示窗口的方法</li></ul>
                            </div>

                        </div>
                        <!--endmain-->
頁: [1]
查看完整版本: Delphi实现获取磁盘空间大小的方法