请问如何删除除了A、C盘、光盘以外的其它盘中所有的AAA.gdb文件,并把第一个AAA.gdb文件保存在C盘的一个指定的路径里???
要在后台处理,整个过程不弹出任何窗口

解决方案 »

  1.   

    Function SearchFileS(SPath,Filter:String;InChildDir : Boolean ; var StrLS : TStringList ) : Boolean;
    var
      i: Integer;
      SearchRec: TSearchRec;
      FileName : String;
    begin
      Result := True;
      if copy(Spath,Length(Spath),1)<>'\' then SPath := SPath+'\';
      try
        i:=FindFirst(SPath+Filter,faAnyFile,SearchRec);
      except
        Result := False;
        exit;
      end;
      while i=0 do begin
        FileName := SearchRec.name;
        if Fileexists(SPath+FileName) then StrLS.Add(SPath+FileName)
        else if (FileName<>'.') and (FileName<>'..') then
           begin
             if InChildDir then  SearchFileS(SPath+FileName,Filter,InChildDir,StrLS)
             else StrLS.Add(SPath+FileName); 
           end
        else if FileName='..' then StrLS.Add(SPath);
        i := FindNext(SearchRec);
      end;
      try
        i:=FindFirst(SPath+'*.*',faDirectory,SearchRec);
      except
        Result := False;
        exit;
      end;
      while i=0 do begin
        FileName := SearchRec.name;
        if Fileexists(SPath+FileName) then 
        else if (FileName<>'.') and (FileName<>'..') then
           begin
             if InChildDir then  SearchFileS(SPath+FileName,Filter,InChildDir,StrLS)
             else StrLS.Add(SPath+FileName); 
           end;
    //    else if FileName='..' then StrLS.Add(SPath);
        i := FindNext(SearchRec);
      end;
      
    end;使用如下:var
      FileList : TStringList;...
    SearchFileS('D:\','AAA.gdb',True,FileList);
    //保存第一个文件..
    //然后删除
    for i:=0 to FileList.Count-1 do
      DeleteFile(FileList.Strings[i]);