在对文件操作把?帮助里写的很详细阿,findfirst 大意是对指定的文件名及属性搜索目录,返回结果以tsearchrec形式存放
Searches for the first instance of a file name with a given set of attributes in a specified directory.
SDirectory:应该是自己定义的目录把
TSearchRec defines file information searched for by FindFirst or FindNext.
Searches for the first instance of a file name with a given set of attributes in a specified directory.
SDirectory:应该是自己定义的目录把
TSearchRec defines file information searched for by FindFirst or FindNext.
function GetDirectorySize(const ADirectory: string): Integer;
var
Dir: TSearchRec;
Ret: integer;
Path: string;
begin
Result := 0;
Path := ExtractFilePath(ADirectory);
Ret := Sysutils.FindFirst(ADirectory, faAnyFile, Dir);
if Ret<>0 then
begin
ShowMessage('路径输入错误');
exit;
end; try
while ret=0 do
begin
inc(Result, Dir.Size);
if (Dir.Attr in [faDirectory]) and (Dir.Name[1] <> '.') then
Inc(Result, GetDirectorySize(Path + Dir.Name + '\*.*'));
Ret := Sysutils.FindNext(Dir);
end;
finally
Sysutils.FindClose(Dir);
end;
end;