function tform1.countd(cPath:string):longint;
var
sr:tsearchrec;
at:integer;begin
at:=sysutils.faReadOnly+sysutils.faHidden+faSysFile+faVolumeID+faDirectory+faArchive+faAnyFile;
//result:=0;
if findfirst(cpath,at,sr)=0 then
begin
repeat
if sr.name='.' then
continue;
if (sr.Attr and fadirectory) = fadirectory then
countd(sr.Name)
else
result:=sr.Size;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
帮我看一段程序,统计一个目录的大小 ,不知问题在哪里,得到的结果不对,顶者有分!!!!!!!!!!!
var
sr:tsearchrec;
at:integer;begin
at:=sysutils.faReadOnly+sysutils.faHidden+faSysFile+faVolumeID+faDirectory+faArchive+faAnyFile;
//result:=0;
if findfirst(cpath,at,sr)=0 then
begin
repeat
if sr.name='.' then
continue;
if (sr.Attr and fadirectory) = fadirectory then
countd(sr.Name)
else
result:=sr.Size;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
帮我看一段程序,统计一个目录的大小 ,不知问题在哪里,得到的结果不对,顶者有分!!!!!!!!!!!
解决方案 »
- 一个关于 dbedit 懂的人感觉很简单的问题 谁先解决分就给谁
- 怎样实现treeview---》xml文件 ????
- 如果客户端突然关机,服务器端怎么才能监测到该clientsocket已经掉线?
- 在ServerSocket和ClientSocket中能否获得某个会话Socket的Server端和Client端的Port值?
- 怎么实现对ACCESS数据库查询?非得用到SQL语句吗?新人,急!
- 请教一下用delphi联sql server2000.BDE的详细配置!
- 小第初学DELPHI,想请一高人指点一二。
- 在delphi程序中,如何判断一个字段值(字段可以是日期等任意类型)为空?
- 用Delhpi 6编译5的程序,怎样处理版本不同的问题?
- 一个客户机服务器的问题!
- 大家看看我的封包程序对么
- 求助,如何利用DELPHI实现自动添加网页表单的功能
result:=sr.Size;//这样就没有累加的过程了直接给段程序给你吧:
function GetDirectorySize(Path: String): Integer; //eg. Path = 'c:\temp\'
var
SR: TSearchRec;
begin
Result := 0;
if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
begin
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr = faDirectory) then
Result := Result + GetDirectorySize(Path+Sr.Name+'\')
else
Result := Result + Sr.Size;
while FindNext(sr) = 0 do
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr = faDirectory) then
Result := Result + GetdirectorySize(Path+Sr.Name+'\')
else
Result := Result + Sr.Size;
FindClose(sr);
end;
end;
好晕,result:=sr.Size 这个是目录大小?这个结构体变量的大小~初始化的时候设置~sr.size是文件的大小