How to check whether there are some changes in directory.
File added,
file deleted,
changes made to file.
Thanks,
Milind
Printable View
How to check whether there are some changes in directory.
File added,
file deleted,
changes made to file.
Thanks,
Milind
ANY changes:
Check on the date of the directory.
What changes:
Not so easy......
Try this:
Code:'Author: Aaron Young
'Origin: Vb-World.net forums
'Purpose: Monitor a Directory
'Version: VB5+
You can use the FindFirstChangeNotification() and
FindNextChangeNotification() API's to monitor a directory
for file changes including creation of new files, i.e.
Private Declare Function WaitForSingleObject _
Lib "kernel32" (ByVal hHandle As Long, ByVal _
dwMilliseconds As Long) As Long
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 Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
Private Const FILE_NOTIFY_CHANGE_LAST_WRITE As Long = &H10
Private Const FILE_NOTIFY_CHANGE_CREATION As Long = &H40
Private Sub WaitForFileActivity(ByVal sDirectory As String)
Dim lHandle As Long
Dim lReturn As Long
lHandle = FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_LAST_WRITE) 'if something's written to a file
'or FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_CREATION ) 'if a file is being created
'or FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_FILE_NAME)
Do
lReturn = WaitForSingleObject(lHandle, 1)
Call FindNextChangeNotification(lHandle)
DoEvents
Loop While lReturn <> 0
End Sub
Private Sub Command1_Click()
WaitForFileActivity "C:\"
MsgBox "Change", vbSystemModal
End Sub