Monday, September 19, 2011

Mengetahui jumlah File dalam forlder dengan delphi

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

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

procedure TForm1.Button1Click(Sender: TObject);
begin
//Edit1.Text := IntToStr(GetFilesCount('c:\windows\', '*.bmp'));
Edit1.Text := IntToStr(GetFilesCount('c:\My Documents', '*.*'));
end;

end.

No comments:

Post a Comment