//删除文件和目录
function Delpath(AFilePath: String): Boolean; stdcall;
var
i: integer;
fpath: String;
PathList: TStringList;
procedure DelFile(AFilePath: String);
var
fpath: String;
srec: TSearchRec;
begin
if Not DirectoryExists(AFilePath) then
Exit;
PathList.Add(AFilePath);
fpath := AFilePath + '/*.*';
if 0 = FindFirst(fpath, faAnyFile, srec) then
begin
if (srec.Name<>'.')and(srec.Name<>'..') then
begin
if (srec.Attr and faDirectory)=faDirectory then
begin
DelFile(AFilePath + '/' + srec.Name);
end
else
DeleteFile(AFilePath + '/' + srec.Name);
end;
while FindNext(srec)=0 do
begin
if (srec.Name<>'.')and(srec.Name<>'..') then
if (srec.Attr and faDirectory)=faDirectory then
DelFile(AFilePath + '/' + srec.Name)
else
DeleteFile(AFilePath + '/' + srec.Name);
end;
end;
FindClose(srec);
end;
begin
Result := False;
if Not DirectoryExists(AFilePath) then
begin
Result := True;
Exit;
end;
PathList := TStringList.Create;
fpath := AFilePath;
if fpath[length(fpath)] = '/' then
fpath := Copy(fpath, 1, length(fpath)-1);
DelFile(fpath);
if PathList.Count > 0 then
for i:=PathList.Count-1 downto 0 do
RmDir(pathlist.Strings[i]);
if Not DirectoryExists(AFilePath) then
Result := True;
end;
function Delpath(AFilePath: String): Boolean; stdcall;
var
i: integer;
fpath: String;
PathList: TStringList;
procedure DelFile(AFilePath: String);
var
fpath: String;
srec: TSearchRec;
begin
if Not DirectoryExists(AFilePath) then
Exit;
PathList.Add(AFilePath);
fpath := AFilePath + '/*.*';
if 0 = FindFirst(fpath, faAnyFile, srec) then
begin
if (srec.Name<>'.')and(srec.Name<>'..') then
begin
if (srec.Attr and faDirectory)=faDirectory then
begin
DelFile(AFilePath + '/' + srec.Name);
end
else
DeleteFile(AFilePath + '/' + srec.Name);
end;
while FindNext(srec)=0 do
begin
if (srec.Name<>'.')and(srec.Name<>'..') then
if (srec.Attr and faDirectory)=faDirectory then
DelFile(AFilePath + '/' + srec.Name)
else
DeleteFile(AFilePath + '/' + srec.Name);
end;
end;
FindClose(srec);
end;
begin
Result := False;
if Not DirectoryExists(AFilePath) then
begin
Result := True;
Exit;
end;
PathList := TStringList.Create;
fpath := AFilePath;
if fpath[length(fpath)] = '/' then
fpath := Copy(fpath, 1, length(fpath)-1);
DelFile(fpath);
if PathList.Count > 0 then
for i:=PathList.Count-1 downto 0 do
RmDir(pathlist.Strings[i]);
if Not DirectoryExists(AFilePath) then
Result := True;
end;