Показать сообщение отдельно
  #2  
Старый 18.06.2008, 10:12
san-46 san-46 вне форума
Активный
 
Регистрация: 25.04.2008
Сообщения: 383
Репутация: 33
По умолчанию

Код:
procedure TForm1.Button1Click(Sender: TObject);
var
  Path, SpecifiedPath, FileN : String;

  function SameFile(SpecPath, FN : String; Attr : Integer) : string;
  var
    SR : TSearchRec;
    N : String;
  begin
    N := FN;
    Result := SpecPath;
    if Attr and faDirectory > 0 then begin
      Result := '';
      N := '*.*';
    end;

    if FindFirst(SpecPath+N, faAnyFile, SR) = 0 then begin
      repeat
        if (SR.Attr and faDirectory > 0) and (Attr and faDirectory > 0) and
           (SR.Name <> '.') and (SR.Name <> '..') then
        begin
          Result := SameFile(SpecPath+SR.Name+'\', FN, SR.Attr);
          if Result <> '' then
            break;
        end;
        if SR.Name = FN then begin
          Result := SpecPath+SR.Name;
          break;
        end;
      until FindNext(sr) <> 0;
    end else
      Result := '';
    FindClose(sr);
  end;

begin
  //следующие два присвоения для примера
  FileN := '1945.txt';      //искомый файл
  SpecifiedPath := 'D:\TextFiles\';  //путь к заданному каталогу

  //вызов рекурсивной функции для поиска файла в каталогах и 
  //подкаталогах, начиная от заданного каталога
  Path := SameFile(SpecifiedPath, FileN, faDirectory);
  if Path <> '' then begin //файл найден
    Memo1.Lines.Add(Path)
  end;
end;
__________________
Не забывайте делать резервные копии
Ответить с цитированием