unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
ListOfFiles: TStringList;
ListOfFolders: TStringList;
Attributes: Integer;
Message: string;
cbx1 : integer;
begin
cbx1 :=1;
Attributes := faReadOnly;
if cbx1 = 1 then
Attributes := Attributes or faHidden;
ListOfFiles := TStringList.Create;
try
FileUtil.FindAllFiles(ListOfFiles, edtDirectory.Text, '*', False, Attributes);
ListOfFiles.Insert(0, Format('The directory contains %d file(s).', [ListOfFiles.Count]));
Message := ListOfFiles.Text;
finally
ListOfFiles.Free;
end;
if cbx1 = 1 then
begin
ListOfFolders := TStringList.Create;
try
FileUtil.FindAllDirectories(ListOfFolders, edtDirectory.Text, False);
ListOfFolders.Insert(0, Format('And %d folders(s).', [ListOfFolders.Count]));
Message := Message + ListOfFolders.Text;
finally
ListOfFolders.Free;
end;
end;
ShowMessage(Message)
end;
end.
Compile Project, Target: project1.exe: Exit code 1, Errors: 2, Warnings: 1
unit1.pas(44,45) Warning: Symbol "faHidden" is not portable
unit1.pas(47,44) Error: Identifier not found "edtDirectory"
unit1.pas(57,54) Error: Identifier not found "edtDirectory"
Can't find edtDirectory. Is this by any chance a listbox on the form named editDirectory?
The procedure was supplied by Aserge.