How to use FindFirst and FindNext in Delphi?

Question

How to use FindFirst and FindNext in Delphi?

Re: How to use FindFirst and FindNext in Delphi?

The procedure FindFiles locates files in a given directory (folder) and its subdirectories, and adds their complete path to a stringlist. Note that recursion is used: FindFiles calls itself at the end of the procedure!
The meaning of the parameters of FindFiles(FilesList, StartDir, FileMask) is as follows:
* FilesList is a stringlist, that you have to create before calling FindFiles. Afterwards, don't forget to free this stringlist.
* In StartDir you specify the starting directory, including the disk drive. If you want to search an entire disk, specify the root directory (root folder) of that disk, such as C:\ or A:\
* In FileMask you pass the name of the file to find, or a file mask with wildcards ( ? and *).
Examples of use:
Find all files on the entire C: disk with the name 'letter1.doc' :
FindFiles('c:\', 'letter01.doc');
Find all files on the entire C: disk, with a name starting with 'euroen', followed by zero, one or two other characters, and ending with the extension '.dpr' :
FindFiles('d:\', 'euroen??.dpr');
Find all Delphi project files in directory d:\projects and its subdirectories :
FindFiles('d:\projects', '*.dpr');