uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, DirectoryWatch, IniFiles;
type
TMFORM = class(TForm)
procedure FormCreate(Sender: TObject);
procedure OnNotify(const Sender: TObject; const Action: TWatchAction; const FileName: string);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MFORM: TMFORM;
scanfolder : TStrings;
INI : TIniFile;
datei : TextFile;
Watch : TDirectoryWatch;
implementation
{$R *.dfm}
procedure TMFORM.FormCreate(Sender: TObject);
begin
assignfile(datei, ExtractFilePath(Application.ExeName) + 'fw.log');
append(datei);
writeln(datei, DateTimetoStr(now()) + ' Starting App, Path: ' + ExtractFilePath(Application.ExeName) + ', Filename: ' + ExtractFilename(Application.ExeName));
INI := TINIfile.Create(ExtractFilePath(Application.ExeName) + 'dir.ini');
scanfolder := TStringList.Create;
INI.ReadSection('ScanDirectory', scanfolder);
writeln(datei, DateTimetoStr(now()) + ' Reading ini file -> scanfolder: ' + scanfolder[0]);
closeFile(datei);
Watch := TDirectoryWatch.Create;
Watch.WatchOptions := [woFileName];
Watch.WatchActions := [waAdded, waRemoved, waModified, waRenamedOld, waRenamedNew];
Watch.Directory := scanfolder[0];
Watch.OnNotify := OnNotify;
Watch.Start;
end;
procedure TMFORM.OnNotify(const Sender: TObject; const Action: TWatchAction; const FileName: string);
begin
case Action of
waAdded:
begin
assignfile(datei, ExtractFilePath(Application.ExeName) + 'fw.log');
append(datei);
writeln(datei, DateTimetoStr(now()) + ' ' + FileName);
closeFile(datei);
end;
end;
end;