After the call to FindAllFiles you get the names loaded to File_List so there is no need later to use the list-file you saved. You should also add some guards against mishappenings
Agreed, errors will need to be accounted for but I initially wanted just a quick routine to find particular files.
Make it a method of the form.
Alternatively, pass a TStrings reference for FoundFiles:
procedure GetDirectories(FoundFiles: TStrings);
and call it as GetDirectories(MyMemo.Lines).
Whatever you do, *don't_hardcode_a_form_instance* like Form1
Unfortunately, my feeble brain is unable to fathom how I might do that
I did simply add 'TForm1.' before GetDirectories but, as you are probably aware, it then refused to compile.
You are quite correct that I don't need three copies of the list. In fact I don't even need a file written to disk, I just want to display the list in the memo (for now at least), and the +1 was to circumvent a SIGVSEG error - I was multi-tasking (or probably not thinking) and missed the N-1 in the loop -
in fact I originally tried 'for i := 1 to N'
Anyway, the new code is:
procedure FindFiles;
var
n,i : word;
begin
Target := '*'+Form1.Search.Caption+'*.CDR';
File_List := FindAllFiles(DriveLetter+':/',Target,True,faAnyFile);
N := File_List.Count;
Form1.Found.Caption:=IntToStr(N);
Form1.FoundFiles.Lines.AddStrings(File_List);
end;
You'll see that I've added a little more flexibility by creating a TEdit into which I can be specific about some part of the filename that I search for. So this has got me to a working solution for the original problem. I may go on to add error-trapping and even make the 'type' (extension) selectable from a drop-down list - - - - but not tonight (this morning!!)
Thanks for your input Lucamar.