ple*_*103 5 delphi delphi-2010
我用这段代码删除整个目录:
uses
  ShellApi;
function DelDir(dir: string): Boolean;
var
  fos: TSHFileOpStruct;
begin
  ZeroMemory(@fos, SizeOf(fos));
  with fos do
  begin
    wFunc  := FO_DELETE;
    fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
    pFrom  := PChar(dir + #0);
  end;
  Result := (0 = ShFileOperation(fos));
end;
是否有任何标志我可以设置允许永久删除已删除的目录?
通过永久删除,我的意思是它在删除后不会显示在回收站中,因为这是我使用DelDir函数时发生的情况.  
小智 4
尝试设置
FileOpStruct.pTo := nil;
例子:
function DeleteTree(const APath: String): Boolean;
var
  FileOpStruct : TShFileOpStruct;
  ErrorCode: Integer;
begin
  Result := False;
  if DirectoryExists(APath) then begin
    FillChar(FileOpStruct, SizeOf(FileOpStruct), #0);
    FileOpStruct.Wnd := 0;
    FileOpStruct.wFunc := FO_DELETE;
    FileOpStruct.pFrom := PChar(APath + #0#0);
    FileOpStruct.pTo := nil;
    FileOpStruct.fFlags := FOF_SILENT or FOF_NOCONFIRMATION or FOF_NOERRORUI or FOF_NOCONFIRMMKDIR;
    FileOpStruct.lpszProgressTitle := nil;
    ErrorCode := ShFileOperation(FileOpStruct);
    Result := ErrorCode = 0;
  end;
end;