|
-
May 26th, 2006, 05:13 AM
#1
Thread Starter
Lively Member
[RESOLVED] Capture folder events in vb (using api)?
Hi there
i need to watch a folder and capture when a file gets written to it.
I realise you cant do this in vb6, but does anyone know of any (free) com plugins, which i can use to do this
cheers
jamie
-
May 26th, 2006, 05:23 AM
#2
Re: Capture folder events in vb (using api)?
Why not use the FileSystemWatcher component of the VB.NET? It is far more easier than implementing ReadDirectoryChangesWAPI on your own in VB 6.0.
Take a look at this thread on codeguru
http://www.codeguru.com/forum/showth...ectoryChangesW
Alternatively you could use a Timer and the FileSystemObject to check the folder after regular intervals. Youc ould just check the Last Modification Date of the folder to see if anything has changed in it.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 26th, 2006, 05:35 AM
#3
Thread Starter
Lively Member
Re: Capture folder events in vb (using api)?
do you mean to create a com in vb.net, then use it in vb6?
What i need to do, is set off a java application, whihc when finished, adds a file to a specific directory. i do not know when this file will be written, so i need a folder watcher, not via looping as this causes my prog to lock up (thisis what iuse at the moment, checking for file exists)
how would i use a timer?
do you have any links to some good tutorials on this,
cheers
Jamie
-
May 26th, 2006, 05:56 AM
#4
Re: Capture folder events in vb (using api)?
You can put a Timer on the Form and set its Interval property to 60000. Then an event Timer1_Timer will be raised after every one minute (approximately). IN this event you can check for the file and proceed with the processing if it is created or else don't do anything. Something similar to this:
1. Add a Timer to your Form
2. Open Properties window and set the INterval property of the Timer object to 60000
3. Double Click on the Timer and write something similar to this in the code
VB Code:
Private Sub Timer1_Timer()
If Dir("C:\myfolder\myfile.ext") <> "" Then
'the file exists
Else
'this file does not exits
End If
End Sub
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 26th, 2006, 01:07 PM
#5
Re: Capture folder events in vb (using api)?
VB Code:
Option Explicit
'[Originally posted by Aaron Young]
'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
'if something's written to a file
lHandle = FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_LAST_WRITE)
'if a file is being created
'or FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_CREATION)
'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
-
May 27th, 2006, 04:24 AM
#6
Thread Starter
Lively Member
Re: Capture folder events in vb (using api)?
cheers very much guys
Jamie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|