Not logged inRybka Chess Community Forum
Up Topic Rybka Support & Discussion / Aquarium / Script: Recursive File Search
- By Moz (****) Date 2011-03-11 17:45
By itself, this script isn't very useful but it's a good demonstration script and the technique might prove valuable to someone working with Scripter in the future.
[hl=delphi]
{Recursive procedure that scans config\TreeConfig directory
and returns a list of all xml files within the directory structure}
 
var                 
StartPath, SearchFor : String;
sl : TStringList;
 
procedure FileList(Folder:String; SearchMask:String; sl:TStringList);
var Rec : TSearchInfo;
 
begin
  Rec := TSSearchInfo.Create;
  if FindFirst(Folder + '*.*', faAnyFile, Rec) = 0 then
  try
    repeat                                             
    if (Rec.Name <> '.') and (Rec.Name <> '..') then            // Skip if '.' and '..'
       if Rec.Attr and faDirectory > 0 then                   // Check if it's a directory
       FileList(Folder + Rec.Name + '\', SearchMask, sl);   // Recursive call i.e. procedure calls itself!
    until FindNext(Rec) <> 0;
  finally
    FindClose(Rec);
  end;
 
 if FindFirst(Folder + SearchMask, faAnyFile - faDirectory, Rec) = 0 then
  try
    repeat
      sl.Add(Folder + Rec.Name);
    until FindNext(Rec) <> 0;
  finally
    FindClose(Rec);
  end;
end;
 
begin
 
StartPath := Datapath + 'config\TreeConfig\';    //The directory to be searched (trailing backslash required)    
SearchFor := '*.xml';                           //Search mask parameter
 
 sl := TStringList.Create;
 try
 FileList(StartPath, SearchFor, sl);       //Call FileList procedure
 print (sl.Text);
 print ('Files found: ' + IntToStr(sl.Count));
 finally
 sl.Free;
 end;
end.
Up Topic Rybka Support & Discussion / Aquarium / Script: Recursive File Search

Powered by mwForum 2.27.4 © 1999-2012 Markus Wichitill