Try this:


VB Code:
  1. 'Author: Aaron Young (with a few added things from Jop)
  2. 'Origin: Vb-World.net forums
  3. 'Purpose: Monitor a Directory
  4. 'Version: VB5+
  5.  
  6.  
  7. 'You can use the FindFirstChangeNotification() and
  8. 'FindNextChangeNotification() API's to monitor a directory
  9. 'for file changes including creation of new files, i.e.
  10.  
  11.  
  12. Private Declare Function WaitForSingleObject _
  13. Lib "kernel32" (ByVal hHandle As Long, ByVal _
  14. dwMilliseconds As Long) As Long
  15.  
  16. Private Declare Function FindFirstChangeNotification _
  17. Lib "kernel32" Alias "FindFirstChangeNotificationA" _
  18. (ByVal lpPathName As String, ByVal bWatchSubtree As _
  19. Long, ByVal dwNotifyFilter As Long) As Long
  20.  
  21. Private Declare Function FindNextChangeNotification _
  22. Lib "kernel32" (ByVal hChangeHandle As Long) As Long
  23.  
  24. Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
  25. Private Const FILE_NOTIFY_CHANGE_LAST_WRITE As Long = &H10
  26. Private Const FILE_NOTIFY_CHANGE_CREATION As Long = &H40
  27.  
  28. Private Sub WaitForFileActivity(ByVal sDirectory As String)
  29.     Dim lHandle As Long
  30.     Dim lReturn As Long
  31.    
  32.     lHandle = FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_LAST_WRITE) 'if something's written to a file
  33.     'or FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_CREATION) 'if a file is being created
  34.     'or FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_FILE_NAME)
  35.     Do
  36.         lReturn = WaitForSingleObject(lHandle, 1)
  37.         Call FindNextChangeNotification(lHandle)
  38.         DoEvents
  39.     Loop While lReturn <> 0
  40. End Sub
  41.  
  42.  
  43. Private Sub Command1_Click()
  44.     WaitForFileActivity "C:\"
  45.     MsgBox "Change", vbSystemModal
  46. End Sub