加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 永久删除目录

发布时间:2020-12-15 04:13:05 所属栏目:大数据 来源:网络整理
导读:我用这段代码删除整个目录: 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(di
我用这段代码删除整个目录:
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函数时发生的情况.

解决方法

尝试设置

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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读