unit uMain;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.Grids,
Vcl.StdCtrls,
System.Types, System.Threading, System.Generics.Collections, System.ioUtils;
type
TForm1 =
class(TForm)
btnStart: TButton;
Grid: TStringGrid;
Memo1: TMemo;
lblZeitTeil: TLabel;
lblZeitGesamt: TLabel;
procedure btnStartClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
procedure PresentFiles(Files: TList<
String>);
var
Form1: TForm1;
TaskCounter: Integer;
lFiles: TList<
String>;
LTasks: TArray<ITask>;
SuchMaske:
String;
MainVerz, FFiles: TStringDynArray;
implementation
{$R *.dfm}
//---------------------------------------------------------
procedure TForm1.btnStartClick(Sender: TObject);
var
I, AktLine: Integer;
StartFolder:
String;
begin
TaskCounter := 0;
SetLength(LTasks, 10);
lFiles.Clear;
StartFolder := '
C:\FB';
SuchMaske := '
*.*';
// Haupt Verzeichnisse einlesen
MainVerz := TDirectory.GetDirectories(StartFolder, TSearchOption.soTopDirectoryOnly,
nil);
// dann die Dateien im Hauptverzeichnis auflisten
FFiles := TDirectory.GetFiles(StartFolder, SuchMaske, TSearchOption.soTopDirectoryOnly,
nil);
lFiles.AddRange(FFiles);
PresentFiles(lFiles);
// dann alle Dateien in allen den Unterverzeichnissen auflisten
TTask.Run(
procedure
var
Verz:
String;
I: Integer;
begin
for I := 0
to High(MainVerz)
do
Begin
Verz := MainVerz[i];
LTasks[TaskCounter] := TTask.Run(
procedure
begin
// Pro Verzeichnis alle Files auflisten
TThread.Queue(
nil,
procedure
begin
Memo1.Lines.Add('
-----------------------------' + Verz);
lFiles.AddRange(TDirectory.GetFiles(Verz, SuchMaske, TSearchOption.soAllDirectories,
nil));
PresentFiles(lFiles);
end);
System.MonitorEnter(self);
try
TaskCounter := TaskCounter + 1;
finally
System.MonitorExit(self);
end;
end);
End;
end);
end;
//---------------------------------------------------------
//---------------------------------------------------------
Procedure PresentFiles(Files: TList<
String>);
var
i: Integer;
begin
for i := 0
to Files.Count - 1
do
Begin
Form1.memo1.Lines.Add(Files[i]);
End;
lFiles.Clear;
end;
//---------------------------------------------------------
//---------------------------------------------------------
procedure TForm1.FormCreate(Sender: TObject);
begin
lFiles := TList<
string>.Create();
end;
//---------------------------------------------------------
//---------------------------------------------------------
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(lFiles);
end;
//---------------------------------------------------------
end.