| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls, StrUtils; type   TForm1 = class(TForm)     Edit1: TEdit;     Edit2: TEdit;     Button1: TButton;     procedure Button1Click(Sender: TObject);   private     { Private declarations }   public     { Public declarations }   end; var   Form1: TForm1;   function FindFlatFileInParentDir(curPath, sFile: string): string;   function FindFlatFile(curPath, sFile: string): string; implementation {$R *.dfm} function FindFlatFileInParentDir(curPath, sFile: string): string; var   pntPath: string;   FilePath: string;   I: Integer; begin   pntPath := curPath;   While true do begin     FilePath := FindFlatFile(pntPath, sFile);     if FilePath <> '' then begin       Result := FilePath;       Break;     end else begin       if Length(pntPath) <= 3 then Break;       if RightStr(pntPath, 1) = '' then         Delete(pntPath, length(pntPath), 1);       for I := Length(pntPath) downto 1 do begin         if pntPath[I] = '' then begin           Delete(pntPath, I, Length(pntPath));           Break;         end;       end;     end;   end; end; function FindFlatFile(curPath, sFile: string): string; var   sRec: TSearchRec;   sRetCode: Integer;   sPath: string; begin   FillChar(sRec, SizeOf(sRec), #0);   sPath := curPath;   if RightStr(sPath, 1) <> '' then     sPath := sPath + '';   sRetCode := FindFirst(sPath + '*.*', faAnyFile, sRec);   While sRetCode = 0 do begin     if (sRec.Attr and not faDirectory = 0) and (sRec.Name <> '.') and (sRec.Name <> '..') then       Result := FindFlatFile(sPath + sRec.Name, sFile)     else begin       if AnsiEndsText(sRec.Name, sFile) then begin         Result := sPath + sRec.Name ;         Break;       end else begin       end;     end;     sRetCode := FindNext(sRec);   end; end; procedure TForm1.Button1Click(Sender: TObject); begin   Caption := FindFlatFileInParentDir(Edit1.Text, Edit2.Text); end; end. | 
