Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips

#118: How can I receive a number of files in some folder?

Today I want to post tip with small function which allow to calculate a number of files in a specified directory.

function GetFilesCount(Folder, WildCard: string): Integer;
  intFound: Integer;
  SearchRec: TSearchRec;
  Result := 0;
  if (Folder <> '') and (Folder[Length(Folder)] <> '\') then
    Folder := Folder + '\';
  intFound := FindFirst(Folder + WildCard, faAnyFile, SearchRec);
  while (intFound = 0) do
    if not (SearchRec.Attr and faDirectory = faDirectory) then
    intFound := FindNext(SearchRec);

To use:
i := GetFilesCount('d:\', '*.zip'); //retrieve a number of zip-archives
i := GetFilesCount('c:\windows\', '*.bmp'); //retrieve a number of bitmaps
i := GetFilesCount('c:\My Documents', '*.*'); //retrieve a total number of any files

Published: March 14, 2001

See also
ABA Spreadsheet Convert
Fast Document Viewer
Paradox to MS Access converter
Paradox Password Recovery
ExcelFile Viewer
Word Web-stream
ABA Picture Convert
Viewer for MS Outlook Messages
Viewer for TNEF-files (winmail.dat)

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2021, Scalabium Software. All rights reserved.

SMExport/SMImport suites