请问用Delphi如何删除指定目录(5分)

  • 主题发起人 主题发起人
  • 开始时间 开始时间

Unregistered / Unconfirmed
GUEST, unregistred user!
我在做一个安装程序
但不知道如何删除指定目录,有哪位大哥可以指点
谢谢啦!!!
 
◇[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;
 
to 6281517:
我试了,不行啊
你的NormalDir()是自定义函数吧
能不能再帮助解决一下呢?
先谢谢了!!!!
 
uses shellapi;
var
lsPath: string;
FileOp: TSHFileOpStruct;
begin
lsPath := 'c:/temp/';
//删除临时文件
with FileOp do begin
Wnd := 0;
wFunc := FO_DELETE;
pFrom := PChar(lsPath + '*.*' + #0); //取目录,与isFaq没有实际关系
pTo := nil;
fFlags := FOF_SILENT + FOF_NOCONFIRMATION ;
fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
SHFileOperation(FileOp);
end;
 
同意楼上,补充一点:
fflags:=fof_noconfirmation;//表不放入回收站;
 
谢谢热心的朋友们!!!!!
问题在你们的指导下解决了!!!!
特别感谢:
zxb200
6281517
D影子D
谢谢!
 

Similar threads

D
回复
0
查看
959
DelphiTeacher的专栏
D
D
回复
0
查看
893
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
973
DelphiTeacher的专栏
D
后退
顶部