ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Forum AtoutFox : Détecter une modification fichier dans une arborescence   

Sujet

rss Flux RSS des derniers messages

Vous devez vous identifier pour pouvoir poser une question ou répondre.

mar. 11 mars 2014, 10h30
etobis
France France

atoutfox.public.association

Détecter une modification fichier dans une arborescence

Bonjour à tous,

je reviens vers Fox pour un besoin précis en espérant que le forum soit toujours aussi actif !

Je souhaite surveiller une arborescence (lourde) pour y détecter l'ajout/la modification de dossiers/fichiers.
J'ai implémenté ce code qui me détecte bien un événement mais je n'arrive pas à déterminer quel fichier ou dossier à été modifié.
Merci d'avance.

PUBLIC oForm
oForm = CREATEOBJECT("Tform", SYS(2023)) && watching TEMP dir
oForm.Visible = .T.
* end of main

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 WATCHING_INTERVAL 1000  && milliseconds

PROTECTED hNotify, PathBeingWatched

    Width=400
    Height=450
    MaxButton=.F.
    BorderStyle=2
    AutoCenter=.T.
    Caption="Watching directory"

    hNotify=INVALID_HANDLE_VALUE
    PathBeingWatched="c:\folder"

    ADD OBJECT lblTarget As Label WITH Left=10, Top=7, Autosize=.T.
    ADD OBJECT oTimer As Timer WITH Interval=0

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

FUNCTION Init(cPath)
    DECLARE SHORT FindNextChangeNotification IN kernel32 INTEGER hChangeHandle
    DECLARE SHORT FindCloseChangeNotification IN kernel32 INTEGER hChangeHandle
    DECLARE INTEGER FindFirstChangeNotification IN kernel32 STRING lpPathName, INTEGER bWatchSubtree,INTEGER dwNotifyFilter
    DECLARE INTEGER WaitForSingleObject IN kernel32 INTEGER hHandle, INTEGER dwMilliseconds

    THIS.PathBeingWatched = "c:\folder"


    IF Not THIS.StartWatching()
        = MESSAGEBOX("Notification handle error.")
        RETURN .F.
    ENDIF

PROCEDURE Destroy
    THIS.StopWatching

PROTECTED FUNCTION StartWatching
    LOCAL lResult


   _event=1+2+4+8+16+32+64+128

    * no subdirs watched
    THIS.hNotify = FindFirstChangeNotification(THIS.PathBeingWatched, 0,_event)

    lResult = (THIS.hNotify <> INVALID_HANDLE_VALUE)

    IF lResult
        THIS.lblTarget.Caption = "Watched: " + THIS.PathBeingWatched
        THIS.oTimer.Interval = WATCHING_INTERVAL
    ENDIF
RETURN  lResult

PROTECTED PROCEDURE ContinueWatching
    IF FindNextChangeNotification(THIS.hNotify) = 0
        THIS.StopWatching
        = MESSAGEBOX("Request error.")
        THIS.Release
    ENDIF
    THIS.oTimer.Interval = WATCHING_INTERVAL

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

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

PROCEDURE _notify        && triggered on event
    LOCAL cMessage
    ? cMessage

    cMessage = "Notification: " + TTOC(DATETIME())
   && THIS.lblAlert.Caption = cMessage
   && ACTIVATE SCREEN
    ? "MESSAGE : "+cMessage
    THIS.ContinueWatching

PROCEDURE oTimer.Timer
  ?? "*"
    IF THISForm._signaled()
        THISForm._notify
    ENDIF





Permalink : http://www.atoutfox.org/nntp.asp?ID=0000014156
20 286 messages dans le forum • Liste complète des messages

www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2026.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3