begin process at 2008 07 25 20:01:36
1 216 468 membres
421 nouveaux aujourd'hui
14 182 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

Sujet : étecter l'ajout ou la modification d'un fichier sur le disque. [ Archives / Divers ] (ygr2)

étecter l'ajout ou la modification d'un fichier sur le disque. le 31/01/2006 11:47:52

ygr2

Bonjour,
je cherche à coder une application qui permet de détecter l'ajout ou la modification d'un fichier sur le disque.
Je ne souhaitre pas utiliser un timer mais plutot reagir à un évènement (j'ai vu qu il existait la fonction BINDEVENT mais je n'ai pas trouve d exemples).
Merci de votre aide


Re : étecter l'ajout ou la modification d'un fichier sur le disque. le 02/02/2006 12:45:27

Mike Gagnon
Membre Club
Il n'y pas vraiment de timer, mais il faut que tu fasse une surveillance d'une maniere ou d'une autre. L'exemple qui suit surveille la création de fichier et non la création de dossier.

PUBLIC frm
frm = CreateObject ("Tform", SYS(2023)) && surveiller le dossier c:\TEMP
frm.Visible = .T.

DEFINE CLASS Tform As Form
#DEFINE FILE_NOTIFY_CHANGE_FILE_NAME      1
#DEFINE FILE_NOTIFY_CHANGE_DIR_NAME       2
#DEFINE FILE_NOTIFY_CHANGE_ATTRIBUTES     4
#DEFINE FILE_NOTIFY_CHANGE_SIZE           8
#DEFINE FILE_NOTIFY_CHANGE_LAST_WRITE    16
#DEFINE FILE_NOTIFY_CHANGE_LAST_ACCESS   32
#DEFINE FILE_NOTIFY_CHANGE_CREATION      64
#DEFINE FILE_NOTIFY_CHANGE_SECURITY     128
#DEFINE INVALID_HANDLE_VALUE             -1
#DEFINE WAIT_OBJECT_0                     0
#DEFINE watchingInterval               1000  && milliseconds

    Width = 400
    Height = 150
    MaxButton = .F.
    BorderStyle = 2
    Caption = "Surveiller le répertoir"

    hNotify = INVALID_HANDLE_VALUE
    PathBeingWatched = ""
    
    ADD OBJECT lblTarget As Label WITH;
        Left=10, Top=7, Autosize=.T.

    ADD OBJECT lblAlert As Label WITH;
        Left=10, Top=30, Autosize=.T., Caption="Notification:"

    ADD OBJECT tm As Timer WITH Interval = 0

PROCEDURE  Load
    THIS.decl

FUNCTION  Init (lcPath)
    THIS.PathBeingWatched = FULLPATH (lcPath)

    IF Not THIS.startWatching()
        = MESSAGEB ("Notification handle error.")
        RETURN .F.
    ENDIF

PROTECTED FUNCTION  startWatching
    LOCAL lResult

    * no subdirs watched
    THIS.hNotify = FindFirstChangeNotification (;
        THIS.PathBeingWatched, 0,;
        FILE_NOTIFY_CHANGE_FILE_NAME +;
        FILE_NOTIFY_CHANGE_LAST_WRITE )

    lResult = (THIS.hNotify <> INVALID_HANDLE_VALUE)

    IF lResult
        THIS.lblTarget.Caption = "Surveillé: " +;
            THIS.PathBeingWatched
        THIS.tm.Interval = watchingInterval
    ENDIF
RETURN  lResult

PROTECTED PROCEDURE  continueWatching
    IF FindNextChangeNotification (THIS.hNotify) = 0
        THIS.stopWatching
        = MESSAGEB ("Request error.")
        THIS.Release
    ENDIF
    THIS.tm.Interval = watchingInterval

PROTECTED FUNCTION  stopWatching
    THIS.tm.Interval = 0
    IF THIS.hNotify <> INVALID_HANDLE_VALUE
        = FindCloseChangeNotification (THIS.hNotify)
    ENDIF

FUNCTION  _signaled        && return signaled state
RETURN  (WaitForSingleObject(THIS.hNotify, 0) = WAIT_OBJECT_0)

PROCEDURE  _notify        && notify on event
    THIS.lblAlert.Caption = "Notification: " + TTOC(DATETIME())
    THIS.continueWatching

PROCEDURE  tm.Timer
    IF ThisForm._signaled()
        ThisForm._notify
    ENDIF

PROCEDURE  Destroy
    THIS.stopWatching

PROTECTED PROCEDURE  decl
    DECLARE INTEGER FindFirstChangeNotification IN kernel32;
        STRING lpPathName, INTEGER bWatchSubtree, INTEGER dwNotifyFilter

    DECLARE SHORT FindNextChangeNotification IN kernel32 INTEGER hChangeHandle
    DECLARE SHORT FindCloseChangeNotification IN kernel32 INTEGER hChangeHandle

    DECLARE INTEGER WaitForSingleObject IN kernel32;
        INTEGER hHandle, INTEGER dwMilliseconds
ENDDEFINE

 



Mike Gagnon

Re : Détecter l'ajout ou la modification d'un fichier sur le disque. le 02/02/2006 13:56:46

ygr2
Il existe pourtant un évènement Windows déclanché lors de la modification d'un répertoire, mais, à priori, il n'est pas récupérable par FoxPro, en tout cas je n'ai pas trouvé d'exemple. Je pense donc qu'on est donc obligé de "surveiller" le répertoire.
Merci


Classé sous : fichier, disque, ajout, modification, étecter

Participer à cet échange

Pub



Appels d'offres

Animation Flash alimen...
Budget : 6 000€
Intranet client pour t...
Budget : 5 000€
Creation portail video
Budget : 3 000€

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS