uses ShellAPI;function DeleteDir(Path: String): Boolean; var shfRecycleBinStruct: TSHFileOpStruct; begin FillChar(shfRecycleBinStruct,SizeOf(shfRecycleBinStruct),0); with shfRecycleBinStruct do begin wFunc := FO_DELETE; pFrom := PChar(Path); fFlags := FOF_NOCONFIRMATION or FOF_SILENT; end; Result := SHFileOperation(shfRecycleBinStruct) = 0; end;演示: procedure TForm1.Button1Click(Sender: TObject); begin DeleteDir('G:\新建文件夹'); end;———————————————————————————————————— 宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。 ————————————————————————————————————
uses ShellAPI var p:_shfileopstruct; a:integer; begin p.Wnd:=handle; p.wFunc:=FO_delete; p.pFrom:='f:\test'#0#0; //删除f盘的test文件夹 p.pTo:=nil; p.fFlags:=fof_noconfirmation; p.fAnyOperationsAborted:=true; a:=shfileoperation(p); end;
var
shfRecycleBinStruct: TSHFileOpStruct;
begin
FillChar(shfRecycleBinStruct,SizeOf(shfRecycleBinStruct),0);
with shfRecycleBinStruct do
begin
wFunc := FO_DELETE;
pFrom := PChar(Path);
fFlags := FOF_NOCONFIRMATION or FOF_SILENT;
end;
Result := SHFileOperation(shfRecycleBinStruct) = 0;
end;演示:
procedure TForm1.Button1Click(Sender: TObject);
begin
DeleteDir('G:\新建文件夹');
end;————————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
————————————————————————————————————
var
p:_shfileopstruct;
a:integer;
begin
p.Wnd:=handle;
p.wFunc:=FO_delete;
p.pFrom:='f:\test'#0#0; //删除f盘的test文件夹
p.pTo:=nil;
p.fFlags:=fof_noconfirmation;
p.fAnyOperationsAborted:=true;
a:=shfileoperation(p);
end;