Delphi 删除目录(二)
procedure TForm1.BitBtn1Click(Sender: TObject);
var
sr:TsearchRec;
begin
if directoryExists( 'g:\a ') then
begin
if FindFirst( 'g:\a\*.* ',faAnyFile,sr)=0 then
begin
repeat
deleteFile( 'g:\a\ '+sr.Name);
until FindNext(sr) <> 0;
Findclose(sr);
end
else
CreateDir( 'g:\a ');
end
else
CreateDir( 'g:\a ');
end;
var
sr:TsearchRec;
begin
if directoryExists( 'g:\a ') then
begin
if FindFirst( 'g:\a\*.* ',faAnyFile,sr)=0 then
begin
repeat
deleteFile( 'g:\a\ '+sr.Name);
until FindNext(sr) <> 0;
Findclose(sr);
end
else
CreateDir( 'g:\a ');
end
else
CreateDir( 'g:\a ');
end;
sysutils
procedure DeleteDirFile(ADir: string);
var
sr: TsearchRec;
begin
if not DirectoryExists(ADir) then Exit;
try
if FindFirst(ADir + '*.*', faAnyFile , sr) = 0 then
begin
repeat
DeleteFile(PAnsiChar(ADir + sr.Name));
until FindNext(sr) <> 0;
end;
finally
FindClose(sr);
end;
end;