我用以下代码,path是要删除的路径,无论删哪个目录,都提示正在使用不能删除
是什么问题呢?
    with Opstrc do
    begin
      Wnd:=handle;
      wFunc:=FO_DELETE;
      pfrom:=PChar(path+'\'+#0);
      pTo:=nil;
      fFlags:=FOF_ALLOWUNDO+FOF_NOCONFIRMATION;
      hNameMappings:=nil;
      lpszProgressTitle:='正在删除文件夹';
      fAnyOperationsAborted:=False;
    end;
    if SHFileOperation(Opstrc)<>0 then
       showmessage('wrong');

解决方案 »

  1.   

    pfrom:=PChar(path+'\'+#0);改为 pfrom:=PChar(path+#0);
      

  2.   

    with SHFILEOPSTRUCT do
            begin
              Wnd:=Form1.Handle;
              WFunc:=FO_DELETE;
              pFrom:=PChar(Dir);
              fFlags:=FOF_ALLOWUNDO;
            end;
          SHFileOperation(SHFileOPStruct);
      

  3.   

    如果文件夹里面只有文件的话下面可以一试;
    var
      s:string;
      FSearchRec:TSearchRec;
      FindResult:ShortInt;
    begin
            s:=ExtractFilePath(ParamStr(0))+'Temp\';
            FindResult:=FindFirst(s+'*.*',faAnyFile,FSearchRec);
            try
              while FindResult=0 do
                begin
                  DeleteFile(s+FSearchRec.Name);
                  FindResult:=FindNext(FSearchRec);
                end;
            finally
              FindClose(FSearchRec);
            end;
            RemoveDir(s);
    end;
      

  4.   

    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;
      

  5.   

    以上的方法都试过了,还是不行,yuhouyangguang(雨后阳光) 的可以,但是我想用SHFileOperation删除,可以同时删掉多级的目录,大家再帮帮忙吧
      

  6.   

    我在D6下通过改正你的代码已测试通过
    pfrom:=PChar(path+'\'+#0);改为 pfrom:=PChar(path+#0);
      

  7.   

    to:WWWWA(aaaa) 
    是我原来的代码么?我也改了啊,可是还是同样的错误啊,奇怪
      

  8.   

    问题已经找到了,是我在列目录的时候没有closefind()
    导致这些目录处于打开状态
    我的代码和上面几位的代码都是正确的
    结了