function DelFlashFN(sPath: string): boolean; var sr: TSearchRec; FileAttrs: Integer; begin result := false; FileAttrs := faArchive; //faAnyFile; if FindFirst(sPath + '*.*', FileAttrs, sr) = 0 then begin repeat DeleteFile('.\Dsk\' + sr.Name); until FindNext(sr) <> 0; FindClose(sr); end; result := true; end;
sPath 修改為你要刪除的路徑, 代碼有點小錯, 修改如下: function DelFlashFN(sPath: string): boolean; var sr: TSearchRec; FileAttrs: Integer; begin result := false; FileAttrs := faArchive; //faAnyFile; if FindFirst(sPath + '*.*', FileAttrs, sr) = 0 then begin repeat DeleteFile(sPath + sr.Name); until FindNext(sr) <> 0; FindClose(sr); end; result := true; end;
//删除文件夹 //用windows api procedure deltree(str: string); var T: TSHFileOpStruct; P: string; begin p := str; with T do begin Wnd := 0; wFunc := FO_DELETE; pFrom := Pchar(P + #0); pTo := Pchar(P + #0); //pTo := nil; fFlags := FOF_ALLOWUNDO + FOF_NOCONFIRMATION + FOF_NOERRORUI; //标志表明允许恢复,无须确认并不显示出错信息 hNameMappings := nil; lpszProgressTitle := '正在删除文件夹'; fAnyOperationsAborted := False; end; SHFileOperation(T); end;
procedure DeleteAllFile(soucepath,targetpath:string); var sr;TsearchRec; begin Sourcepath:=includetrailingbackslash(soucepath); targetpath:=includetrailingbackslash(targetpath); if findFirst(soucepath+'\*.*',faanyfile,sr)=0 then begin repeat if (sr.name<>'.') and (sr.name<>'..') then begin if sr.attr<>fadirctory then begin DeleteFile(sr.name); end else begin GetALLfILES(sourcepath+sr.name); end;
var
sr: TSearchRec;
FileAttrs: Integer;
begin
result := false;
FileAttrs := faArchive; //faAnyFile; if FindFirst(sPath + '*.*', FileAttrs, sr) = 0 then
begin
repeat
DeleteFile('.\Dsk\' + sr.Name);
until FindNext(sr) <> 0;
FindClose(sr);
end;
result := true;
end;
function DelFlashFN(sPath: string): boolean;
var
sr: TSearchRec;
FileAttrs: Integer;
begin
result := false;
FileAttrs := faArchive; //faAnyFile; if FindFirst(sPath + '*.*', FileAttrs, sr) = 0 then
begin
repeat
DeleteFile(sPath + sr.Name);
until FindNext(sr) <> 0;
FindClose(sr);
end;
result := true;
end;
//用windows api
procedure deltree(str: string);
var
T: TSHFileOpStruct;
P: string;
begin
p := str;
with T do
begin
Wnd := 0;
wFunc := FO_DELETE;
pFrom := Pchar(P + #0);
pTo := Pchar(P + #0);
//pTo := nil;
fFlags := FOF_ALLOWUNDO + FOF_NOCONFIRMATION + FOF_NOERRORUI; //标志表明允许恢复,无须确认并不显示出错信息
hNameMappings := nil;
lpszProgressTitle := '正在删除文件夹';
fAnyOperationsAborted := False;
end;
SHFileOperation(T);
end;
var
sr;TsearchRec;
begin
Sourcepath:=includetrailingbackslash(soucepath);
targetpath:=includetrailingbackslash(targetpath);
if findFirst(soucepath+'\*.*',faanyfile,sr)=0 then
begin
repeat
if (sr.name<>'.') and (sr.name<>'..') then
begin
if sr.attr<>fadirctory then
begin
DeleteFile(sr.name);
end
else
begin
GetALLfILES(sourcepath+sr.name);
end;
end;
end;
end;
end;