回 帖 发 新 帖 刷新版面

主题:[讨论]删除文件夹

procedure mydeletefile(s:string);
var
   sr:tsearchrec;
begin
  if findfirst(s+'\*.*',faanyfile,sr)=0 then
  begin
    if (sr.name<> '.')and(sr.name<>'..') then
     begin
       if sr.Attr=fadirectory then
       begin
          mydeletefile(s+'\'+sr.name);
       end
       else
         deletefile(pchar(s+'\'+sr.name));
      end;
    while findnext(sr)=0 do
    begin
    if (sr.name<> '.')and(sr.name<>'..') then
       if sr.Attr=fadirectory then
       begin
          mydeletefile(s+'\'+sr.name);
       end
      else
      deletefile(pchar(s+'\'+sr.name));
     end;
    findclose(sr);
  end;
end;
这样删除一个文件夹下的所有文件怎么删不掉呀,那里错了呀

回复列表 (共1个回复)

沙发

uses
  shellapi;

strcopy(frombuf,pchar('目录名'));
        if directoryexists(frombuf) then
          begin
             with opstruc do
               begin
                 wnd:=handle;
                 wfunc:=fo_delete;
                 pfrom:=@frombuf;
                 fflags:=FOF_NOCONFIRMATION or FOF_SILENT;
                 fanyoperationsaborted:=false;
                 hnamemappings:=nil;
                 lpszprogresstitle:=nil;
               end;
             shfileoperation(opstruc);               //清除文件
          end;

我来回复

您尚未登录,请登录后再回复。点此登录或注册