|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jan 2000
Città: Prov. di VE
Messaggi: 2713
|
[VB] Monitorare file REAL TIME
Raga...... se avete na idea di come si possa controllare i cambiamenti di un file (qualsiasi...... ma forse mi basta l'ora precisa al secondo però) in REAL TIME (quindi niente cicli, vorrei un evento), mi faccia sapere!
Credo sia da usare una qualche API di Win, ho trovato qcsa ma nn son riuscito a far funzionare niente: VB6 si blocca e tocca terminarlo col task manager..... Boh.... accetto idee e codice! Grazieeeeeeeeeee |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Jan 2000
Città: Prov. di VE
Messaggi: 2713
|
Mi son dimenticato di dire che ho Visual Basic 6...
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Senza cicli o eventi di timer non credo sia una cosa semplice...
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Jan 2000
Città: Prov. di VE
Messaggi: 2713
|
eh già... ho girato una cifra ma niente.... o meglio: avevo trovato un frammento di codice che teoricamente (usando le API) fa quello che cerco, ma sinceramente nn riesco ad usarlo (e si che pare facile, basta passare il percorso+nome del file credo).
Vi posto il codice: Codice:
Private Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4 Private Const FILE_NOTIFY_CHANGE_DIR_NAME = &H2 Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1 Private Const FILE_NOTIFY_CHANGE_SIZE = &H8 Private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10 Private Const FILE_NOTIFY_CHANGE_SECURITY = &H100 Private Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1 Or &H8 Or &H10 Or &H100 Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long Private Declare Function FindNextChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function ResetEvent Lib "kernel32" (ByVal hEvent As Long) As Long Public Sub WaitForFileChange(ByVal fn as String,Optional ByVal flags = FILE_NOTIFY_CHANGE_ALL,Optional ByVal CheckSubDir As Boolean = TRUE,Optional ByVal TimeOut As Long = -1) 'waits until a change occurs in directory fn Dim hNote As Long hNote = FindFirstChangeNotification(fn, CheckSubDir, flags) 'Set the hook WaitForSingleObject hNote, TimeOut 'Wait for the event FindCloseChangeNotification hNote 'Clear the hook End Sub Se qcno ci capisce + di me..... commenti nn ce ne son tanti (forse è semplice, ma nn lo capisco |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Ottimo...ti faccio sapere...
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Jan 2000
Città: Prov. di VE
Messaggi: 2713
|
denghiù!
io ho provato con qcsa del tipo WaitForFileChange("c:\autoexec.bat") ma il risultato è un blocco totale di VB6 |
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Q
Sì...
Intanto non guarda il file, ma un'intera directory... Quindi per monitorare autoexec.bat dovresti sepcificare "C:\"... Io l'ho usato in VC++, ma in ogni caso presuppone un'attesa infinita... Per non avere attesa infinita devi: 1) richiamare FindFirstChangeNotification una sola volta all'inizio del programma...e metterti da parte il valore di ritorno... hNote = FindFirstChangeNotification("C:\", False, FILE_NOTIFY_CHANGE_LAST_WRITE) 2) ogni tot secondi (con un evento timer) devi richiamare una funzione che fa una cosa del genere: Private Const WAIT_TIMEOUT = &H102 Private Const WAIT_OBJECT_0 = &H0 res = WaitForSingleObject(hNote, 1) 'attende 1 millisecondo If res = WAIT_OBJECT_0 Then 'controlli se autoexec.bat è stato modificato (basta controllare la data dell'ultima scrittura) Else If res = WAIT_TIMEOUT Then 'non c'è stata alcuna modifica a tutta la directory Else 'errore del programma End If FindNextChangeNotification(hNote) 'si ritorna a monitorare la directory |
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Purtroppo se non vuoi usare un timer devi crearti un altro thread...
|
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Jan 2000
Città: Prov. di VE
Messaggi: 2713
|
già... uhmmm........ vedrò che posso fare.... anche perchè FORSE ho risolto il problema in un altro modo senza usare il monitoraggio real time. Cmq questo sistema, è sicuramente meno efficiente (e ho anche messo un array con dimensione..... mi tocca controllarlo tutto anche se nn c'è un cassio........ ghgh... ma intanto PARE funzionare
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 11:04.



















