如上

解决方案 »

  1.   

    你参考这个,这个是遍历某目录及其所有子目录、文件,并删除的函数。有你要的东西procedure Fun_DeleteDir(sDirectory:String);stdcall;//删除目录和目录下得所有文件和文件夹
    var
      sr:TSearchRec;
      sPath,sFile: String;
    begin
      if Copy(sDirectory,Length(sDirectory),1) <> '\' then
        sPath := sDirectory + '\'
      else
        sPath := sDirectory;  if SysUtils.FindFirst(sPath+'*.*',faAnyFile, sr) = 0 then
      begin
        repeat
          sFile:=Trim(sr.Name);
          if sFile='.' then Continue;
          if sFile='..' then Continue;      sFile:=sPath+sr.Name;
          if (sr.Attr and faDirectory)<>0 then
            Fun_DeleteDir(sFile)
          else
          if (sr.Attr and faAnyFile) = sr.Attr then
          begin
            try
              DeleteFile(PAnsiChar(sFile));   //删除文件
            except
              ;
            end;
          end;
        until SysUtils.FindNext(sr) <> 0;
        SysUtils.FindClose(sr);
      end;
      try
        RemoveDir(sPath);
      except
        ;
      end;
    end;