Results 1 to 3 of 3

Thread: Changes in directory

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    53
    How to check whether there are some changes in directory.


    File added,
    file deleted,
    changes made to file.



    Thanks,


    Milind

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    ANY changes:
    Check on the date of the directory.

    What changes:
    Not so easy......

  3. #3
    Guest
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width