有两个结构相同的对应目录(子目录个数相同,对应目录名相同),都是:两层,一个父目录下面多个子目录,子目录下只有文件要做的就是:把那些对应文件作比较,同名的删除。请问高手们如何解决?
可以用delphi自己的api:routine做吗?

解决方案 »

  1.   

    用FindFirst, FindNext遍历目录就可以了!!!要是用递归算法!!!
      

  2.   

    FindFirst要文件名路径做参数,我不知道文件名丫?
      

  3.   

    还可以用FindFirst吗?(设置相应参数?)
      

  4.   

    递归方法去做,用FINDFIRST和FINDNEXT
      

  5.   

    请各位大侠详细说明,thx!可以做到吗?
    第一层循环遍历目录,第二层遍历子目录中的所有文件。。?
      

  6.   

    当然可以做到了,你看看<windows优化大师>中的垃圾文件删除功能,先要准备文件列表(把所有的文件名放入list中),然后才是一个个的判断是不是垃圾文件 。别人都可以,你为什么不行?多试吧。
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);var
      sr: TSearchRec;
      FileAttrs: Integer;
    begin
      StringGrid1.RowCount := 1;
      if CheckBox1.Checked then
        FileAttrs := faReadOnly
      else
        FileAttrs := 0;
      if CheckBox2.Checked then
        FileAttrs := FileAttrs + faHidden;
      if CheckBox3.Checked then
        FileAttrs := FileAttrs + faSysFile;
      if CheckBox4.Checked then
        FileAttrs := FileAttrs + faVolumeID;
      if CheckBox5.Checked then    FileAttrs := FileAttrs + faDirectory;
      if CheckBox6.Checked then
        FileAttrs := FileAttrs + faArchive;
      if CheckBox7.Checked then    FileAttrs := FileAttrs + faAnyFile;  with StringGrid1 do
      begin
        RowCount := 0;    if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then    begin
          repeat
            if (sr.Attr and FileAttrs) = sr.Attr then
            begin
            RowCount := RowCount + 1;
            Cells[1,RowCount-1] := sr.Name;
            Cells[2,RowCount-1] := IntToStr(sr.Size);
            end;
          until FindNext(sr) <> 0;
          FindClose(sr);
        end;
      end;
    end;
      

  8.   

    谢谢各位大侠!
    本问题关键一个在于一开始没看到faDirectory这个常量,一个在于FindFirst的说明也没仔细看,里面有说如果第一个参数是xxxx路径\*.* ,则可遍历所有
    Anyway谢谢大家帮助,启迪我btw还有那位有其它方法解决该问题??请示之,thx!!!