How could I do that using API calls? I would just to be notified, when there are any new files in certain directory (and which files)... using API of course. Any ideas?
Thank you very much in advance !
Printable View
How could I do that using API calls? I would just to be notified, when there are any new files in certain directory (and which files)... using API of course. Any ideas?
Thank you very much in advance !
Try this:
VB Code:
'Author: Aaron Young (with a few added things from Jop) '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
Thanx Matthew, I think that's what I wanted !! I'll put that "waitforactivity" in timer (or is there any other solution...that folder is checked constantly?), I think that should work.
Thanx again !
No need for a timer. It's already looping, just put that in a Command Button called "Watch" or even in the Form_Load() event.