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
Printable View
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
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.
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
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
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
cheers very much guys
Jamie