What edits should be made to the code in order to search only in the current directory without subdirectories?
procedure Scaserch(StartFolder, Mask: string; List: TStrings; ScanSubFolders: Boolean = True); var SearchRec: TSearchRec; FindResult: Integer; begin List.BeginUpdate; try StartFolder := IncludeTrailingBackslash(StartFolder); FindResult := FindFirst(StartFolder + '*.*', faAnyFile, SearchRec); try while FindResult = 0 do with SearchRec do begin if (Attr and faDirectory) <> 0 then begin if ScanSubFolders and (Name <> '.') and (Name <> '..') then Scaserch(StartFolder + Name, Mask, List, ScanSubFolders); end else begin if MatchesMask(Name, Mask) then List.Add(StartFolder + Name); end; FindResult := FindNext(SearchRec); end; finally FindClose(SearchRec); end; finally List.EndUpdate; end; end; I connect this way:
Scaserch(SelectedFolder, '*.txt', ListBox1.Items);