Witam, potrzebuję znaleźć plik znajdujący się w katalogu domowym użytkownika w C:\Users\Marcin\AppData\Roaming\ - katalog AppData\Roaming\ jest katalogiem z atrybutem hiden. Na stronie 4programmers.net znalazłem kilka linijek kodu który sprawnie i bezbłędnie wyszukuje pliki, ale w przeszukiwaniu nie uwzględnia katalogów z atrybutem hiden. Czy możecie mi pomóc w rozwiązaniu tego problemu. Poniżej ten kod co wyszukuje:
procedure TForm1.FileSearch(const PathName, FileName : string; const InDir : boolean);
var Rec : TSearchRec;
Path, CurFile, AllFiles : string;
i: integer;
begin
Path := IncludeTrailingBackslash(PathName);
AllFiles:=FileName;
while AllFiles<>'' do begin
i:=pos(';', AllFiles);
if i=0 then begin
CurFile:=Trim(AllFiles);
AllFiles:='';
end else begin
CurFile:=Trim(Copy(AllFiles, 1, i-1));
Delete(AllFiles, 1, i);
end;
if FindFirst(Path + CurFile, faAnyFile, Rec) = 0 then
try
repeat
ListBox1.Items.Add(Path + Rec.name);
until FindNext(Rec) <> 0;
finally
FindClose(Rec);
end;
end;
if not InDir then Exit;
if FindFirst(Path + '*.*', faDirectory, Rec) = 0 then
try
repeat
if { (Rec.Attr and faDirectory) and } (Rec.name <> '.') and (Rec.name <> '..') then
FileSearch(Path + Rec.name, FileName, True);
until FindNext(Rec) <> 0;
finally
FindClose(Rec);
end;
end;
Kod wywołujący wyszukiwanie pliku:
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
ListBox1.Clear;
FileSearch(Edit1.Text,Edit2.Text, CheckBox1.State in [cbChecked]);
end;
dodanie znaczników <code class="delphi"> - Furious Programming