下面是我用来取硬盘空间和剩余空间的代码procedure TForm1.checkdisk;
var
F1:textfile;
total_space,free_space:string;
spc,bps,nofc,tnoc:longword;
ch:char;
i:integer;
begin
//check disk space
AssignFile(F1,'c:\space.txt');
rewrite(F1);
for ch:='B' to 'Z' do begin
i:=getdrivetype(pchar(ch+':\'));
if i=DRIVE_FIXED then begin
if getdiskfreespace(pchar(ch+':\'),spc,bps,nofc,tnoc) then begin
total_space:=inttostr((spc*bps*tnoc) div (1024*1024))+'MB';
free_space:=inttostr((spc*bps*nofc) div (1024*1024))+'MB';
writeln(F1,ch+':'+free_space+'/'+total_space);
end; end;
end;
closefile(F1);
end;运行结果为:
(space.txt)
C:426MB/3491MB
D:992MB/1979MB令我感到疑惑的是:取的c:盘总空间和实际空间符合可是!!!!D:盘可用空间为992MB,实际总空间为6093MB,
为什么取得的D:盘总空间和实际空间不符合???望众大侠能帮帮小弟!
var
F1:textfile;
total_space,free_space:string;
spc,bps,nofc,tnoc:longword;
ch:char;
i:integer;
begin
//check disk space
AssignFile(F1,'c:\space.txt');
rewrite(F1);
for ch:='B' to 'Z' do begin
i:=getdrivetype(pchar(ch+':\'));
if i=DRIVE_FIXED then begin
if getdiskfreespace(pchar(ch+':\'),spc,bps,nofc,tnoc) then begin
total_space:=inttostr((spc*bps*tnoc) div (1024*1024))+'MB';
free_space:=inttostr((spc*bps*nofc) div (1024*1024))+'MB';
writeln(F1,ch+':'+free_space+'/'+total_space);
end; end;
end;
closefile(F1);
end;运行结果为:
(space.txt)
C:426MB/3491MB
D:992MB/1979MB令我感到疑惑的是:取的c:盘总空间和实际空间符合可是!!!!D:盘可用空间为992MB,实际总空间为6093MB,
为什么取得的D:盘总空间和实际空间不符合???望众大侠能帮帮小弟!
下面是我改过的,用了一个API:GetFreeSpaceEX
粘上去就能用
F1:textfile;
total_space,free_space:string;
freeavailable,totalspace,totalfree:int64;
ch:char;
i:integer;
begin
k:=0;//check disk space
AssignFile(F1,'c:\space.txt');
rewrite(F1);
for ch:='B' to 'Z' do begin
i:=getdrivetype(pchar(ch+':\'));
if i=DRIVE_FIXED then begin
if getdiskfreespaceex(pchar(ch+':\'),freeavailable,totalspace, @totalfree) then
begin
total_space:=floattostr(totalspace div (1024*1024))+'MB';
free_space:=inttostr(totalfree div (1024*1024))+'MB';
writeln(F1,ch+':'+free_space+'/'+total_space);
end; end;
end;