-
Hi, I am writing a watch program. The program should look over a folder and if somebody add/delete or rename any file, the program give them a message and log the error. I have been successful with the add/delete but I havn't had any luck detecting if anybody has rename the files. I am using a file control.
-
Loop regulary trough the items, and compare them to static copy of it in a method.
-
Doesn't work!
Thanks for the help but how would I make an static copy of the item when they are dynamic and changable by the user?
-
Well you could redim it...
Static strcopy$()
Redim preserve strcopy(list.listcount)
-
You can use the FindFirstChangeNotification() API to have you program wait for a Change to be made before going out to check and see what file it was, i.e.
Code:
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 FindNextChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function WaitForSingleObjectEx Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long, ByVal bAlertable As Long) As Long
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_LAST_WRITE = &H10
Private Const FILE_NOTIFY_CHANGE_SECURITY = &H100
Private Const FILE_NOTIFY_CHANGE_SIZE = &H8
Private lNotifyHandle As Long
Private bStop As Boolean
Private Sub Command1_Click()
Dim lReturn As Long
bStop = False
lNotifyHandle = FindFirstChangeNotification("C:\Test\", 1, FILE_NOTIFY_CHANGE_FILE_NAME)
If lNotifyHandle < 1 Then MsgBox "Couldn't get a Notify Handle": Exit Sub
While Not bStop
lReturn = WaitForSingleObjectEx(lNotifyHandle, 1, True)
If lReturn = 0 Then
Text1.SelText = "Something Changed" & vbCrLf
Call FindNextChangeNotification(lNotifyHandle)
End If
DoEvents
Wend
Call FindCloseChangeNotification(lNotifyHandle)
End Sub
Private Sub Command2_Click()
bStop = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
bStop = True
End Sub
Regards,
- Aaron.