Savoir lorsqu'un nouveau fichier est crée

function WaitForFile(FileName: string): Boolean;
{Wait for a file to be created. Tracks the directory were the file will be created.
Returns true if file exists, false on error.}
var
WaitHandle: THandle;
begin
Result := False; {Let's assume we failed}
WaitHandle := FindFirstChangeNot if ication(PChar(ExtractFilePath(FileName)),
False, FILE_NOTIFY_CHANGE_FILE_NAME);
if (INVALID_HANDLE_VALUE = WaitHandle) then
begin
{The path to the file does not exists}
Exit;
end;
repeat
if WaitForSingleObject(WaitHandle, INFINITE) = WAIT_OBJECT_0 then
begin {Something happenned in the directory}
if FileExists(FileName) then
begin
result := True;
Break; {My file has been created, exit}
end;
{My file is not there, keep on}
if not FindNextChangeNot if ication(WaitHandle) then
begin
{Something happened to the directory, maybe it was deleted}
Break;
end;
end;
until
False;
FindCloseChangeNot if ication(WaitHandle);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if WaitForFile('c: ewfile.dat') then
showmessage('newfile a été crée !!!');
end;
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour17/12/2004
VisualisationVu 1137 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Fichier
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur