View Single Post
Old Mar 8th, 2010, 8:22 PM   #4
abdul.gafur
Trying to be a Real Coder
 
abdul.gafur's Avatar
 
Join Date: Feb 2010
Location: Salo, Riau, Indonesia
Posts: 112
Rep Power: 1 abdul.gafur is on a distinguished road
Send a message via Yahoo to abdul.gafur
Re: Performing a file search, and then uploading results to a backup server

delphi Syntax (Toggle Plain Text)
  1. // Recursive procedure to build a list of files
  2. procedure FindFiles(FilesList: TStringList; StartDir, FileMask: string);
  3. var
  4. SR: TSearchRec;
  5. DirList: TStringList;
  6. IsFound: Boolean;
  7. i: integer;
  8. begin
  9. if StartDir[length(StartDir)] <> '\' then
  10. StartDir := StartDir + '\';
  11.  
  12. { Build a list of the files in directory StartDir
  13.   (not the directories!) }
  14.  
  15. IsFound :=
  16. FindFirst(StartDir+FileMask, faAnyFile-faDirectory, SR) = 0;
  17. while IsFound do begin
  18. FilesList.Add(StartDir + SR.Name);
  19. IsFound := FindNext(SR) = 0;
  20. end;
  21. FindClose(SR);
  22.  
  23. // Build a list of subdirectories
  24. DirList := TStringList.Create;
  25. IsFound := FindFirst(StartDir+'*.*', faAnyFile, SR) = 0;
  26. while IsFound do begin
  27. if ((SR.Attr and faDirectory) <> 0) and
  28. (SR.Name[1] <> '.') then
  29. DirList.Add(StartDir + SR.Name);
  30. IsFound := FindNext(SR) = 0;
  31. end;
  32. FindClose(SR);
  33.  
  34. // Scan the list of subdirectories
  35. for i := 0 to DirList.Count - 1 do
  36. FindFiles(FilesList, DirList[i], FileMask);
  37.  
  38. DirList.Free;
  39. end;
  40.  
  41. // Example: how to use FindFiles
  42. procedure TForm1.ButtonFindClick(Sender: TObject);
  43. var
  44. FilesList: TStringList;
  45. begin
  46. FilesList := TStringList.Create;
  47. try
  48. FindFiles(FilesList, EditStartDir.Text, EditFileMask.Text);
  49. ListBox1.Items.Assign(FilesList);
  50. LabelCount.Caption := 'Files found: ' + IntToStr(FilesList.Count);
  51. finally
  52. FilesList.Free;
  53. end;
  54. end;
source : http://www.festra.com/eng/snip04.htm

FindFiles is recursive. See part of FindFIles' code
// Scan the list of subdirectories
for i := 0 to DirList.Count - 1 do
FindFiles(FilesList, DirList[i], FileMask);


It is for search the entire folders
__________________
just a drop of dew in the morning
abdul.gafur is offline   Reply With Quote