Witam, szukam kopii pliku na dysku lecz mam problem, mam 2 funkcje, jedna szuka pliku, gdy go znajdzie zapisuje jego nazwę,rozmiar i czas ost. modyfikacji:
procedure TForm1.FileSearchPrev(const PathName, FileName : string);
var
sr : TSearchRec;
sx : Integer;
Path : String;
begin
Path:=IncludeTrailingBackslash(PathName);
sx := FindFirst(Path + FileName, faAnyFile - faDirectory, sr);
if sx = 0 then
begin
try
repeat
//dane
nazwa:=sr.Name;
time:=sr.Time;
rozmiar:=sr.Size;
exit;
until FindNext(sr) <>0
finally
FindClose(sr);
end;
end;
if FindFirst(Path + '*.*', faDirectory, sr) = 0 then
try
repeat
if ((sr.Attr and faDirectory) <> 0) and (sr.Name<>'.') and (sr.Name<>'..') then
FileSearch(Path + sr.Name, FileName);
until FindNext(sr) <> 0;
finally
FindClose(sr);
end;
end; // wyszukiwanie
Ona działa wykonuje swoje zadanie.
2 funkcja to lekko zmofyfikowana funkcja powyżej, która ma mi wyszukać kopię tego pliku, doda wynik jeżeli zgadza się rozmiar, nazwa oraz data.
procedure TForm1.FileSearch(const PathName, FileName : string);
var
sr1 : TSearchRec;
sx : Integer;
Path : String;
begin
Path:=IncludeTrailingBackslash(PathName);
sx := FindFirst(Path + FileName, faAnyFile - faDirectory, sr1);
if sx = 0 then
begin
try
repeat
if (nazwa = sr1.Name) //and (rozmiar = sr.Size) //and (time = sr.Time)
then
Memo1.Lines.Add(Path + sr1.Name);
until FindNext(sr1) <>0
finally
FindClose(sr1);
end;
end;
if FindFirst(Path + '*.*', faDirectory, sr1) = 0 then
try
repeat
if ((sr1.Attr and faDirectory) <> 0) and (sr1.Name<>'.') and (sr1.Name<>'..') then
FileSearch(Path + sr1.Name, FileName);
until FindNext(sr1) <> 0;
finally
FindClose(sr1);
end;
end; // wyszukiwanie
Korzystam z gotowej pętli którą znalazłem w internecie dla przeszukiwania katalogów, myślę, że błąd może leżeć gdzieś tu, możecie zerknąć, jest to fragment kodu z funkcji powyżej?
if FindFirst(Path + '*.*', faDirectory, sr1) = 0 then
try
repeat
if ((sr1.Attr and faDirectory) <> 0) and (sr1.Name<>'.') and (sr1.Name<>'..') then
FileSearch(Path + sr1.Name, FileName);
until FindNext(sr1) <> 0;
finally
FindClose(sr1);
end;
end;