我想删除C盘下的wawa 文件夹,   下面是我写的代码,可以运行, 但是不可以删除,  谁帮我改一下吧,  最好是全部代码贴出来。谢谢了啊!    已经弄了半天了还是不行, 帮帮我吧!
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,shellapi;type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}function DelDirectory(const Source: string): boolean;     //
var   //
    fo: TSHFILEOPSTRUCT;    //
begin    //
    FillChar(fo, SizeOf(fo), 0);    //
    with fo do    //
    begin    //
      Wnd    := 0;    //
      wFunc := FO_DELETE;    //
      pFrom := PChar('c:\wawa' + #0);    //
      pTo    := #0#0;    //
      fFlags := FOF_NOCONFIRMATION + FOF_SILENT;    //
    end;    //
    Result := (SHFileOperation(fo) = 0);    //
end;    //
end.    打了注释的地方就是我加的代码。

解决方案 »

  1.   

    var   dirinfo:tsearchrec;r:integer;   
      begin   
      r:=SysUtils.FindFirst('c:\test\*.*',faanyfile,dirinfo);   
      while   r=0   do   
      begin   
      if   ((dirinfo.attr   and   fadirectory<>fadirectory)and   (dirinfo.attr   and   favolumeid<>favolumeid))   then   
      if   deletefile(pchar('c:\test\'+dirinfo.name))=false   then   
      showmessage('unable   to   delete:c:\test\'+dirinfo.name);   
      r:=findnext(dirinfo);   
      end;   
      sysutils.findclose(dirinfo);   
      if   removedirectory('c:\test')=false   then   
      showmessage('unable   to   delete:c:\test');   
      end;
      

  2.   

    确保文件目录里的文件没人使用,否则就要考虑用movefileex了
      

  3.   

    谢谢大家的回答,    1楼你贴的代码我看不懂!  我的意思就是用这个代码!   我是新手,这么简单的都不会,   要加油啊!   哇哇~~~~~~~function DelDirectory(const Source: string): boolean;
    var
        fo: TSHFILEOPSTRUCT;
    begin
        FillChar(fo, SizeOf(fo), 0);     
        with fo do   
        begin
          Wnd    := 0;
          wFunc := FO_DELETE;       
          pFrom := PChar(Source + #0);   
          pTo    := #0#0;
          fFlags := FOF_NOCONFIRMATION + FOF_SILENT;      
        end;
        Result := (SHFileOperation(fo) = 0);     
    end;