电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> delphi技术>>Delphi基础开发技巧(5):

Delphi基础开发技巧(5)

来源:远方网络 | 2005-12-31 9:27:41 | (有1776人读过)

[DELPHI]如何清空一个目录

function EmptyDirectory(TheDirectory :String ; Recursive : Boolean) :

Boolean;

var

SearchRec : TSearchRec;

Res : Integer;

begin

Result := False;

TheDirectory := NormalDir(TheDirectory);

Res := FindFirst(TheDirectory + '*.*', faAnyFile, SearchRec);

try

while Res = 0 do

begin

if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then

begin

if ((SearchRec.Attr and faDirectory) > 0) and Recursive

then begin

EmptyDirectory(TheDirectory + SearchRec.Name, True);

RemoveDirectory(PChar(TheDirectory + SearchRec.Name));

end

else begin

DeleteFile(PChar(TheDirectory + SearchRec.Name))

end;

end;

Res := FindNext(SearchRec);

end;

Result := True;

finally

FindClose(SearchRec.FindHandle);

end;

end;

[DELPHI]如何计算一个目录的大小

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 <> NO_ERROR then exit;

try

while ret=NO_ERROR 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;



delphi技术热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号