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.Regards,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
- Aaron.




Reply With Quote