PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Capture folder events in vb (using api)?-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] Capture folder events in vb (using api)?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    80

    Resolved [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

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    80

    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

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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:
    1. Private Sub Timer1_Timer()
    2.     If Dir("C:\myfolder\myfile.ext") <> "" Then
    3.         'the file exists
    4.     Else
    5.         'this file does not exits
    6.     End If
    7. End Sub
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Capture folder events in vb (using api)?

    VB Code:
    1. Option Explicit
    2.  
    3. '[Originally posted by Aaron Young]
    4. 'You can use the FindFirstChangeNotification() and
    5. 'FindNextChangeNotification() API's to monitor a directory
    6. 'for file changes including creation of new files, i.e.
    7.  
    8. Private Declare Function WaitForSingleObject _
    9. Lib "kernel32" (ByVal hHandle As Long, ByVal _
    10. dwMilliseconds As Long) As Long
    11.  
    12. Private Declare Function FindFirstChangeNotification _
    13. Lib "kernel32" Alias "FindFirstChangeNotificationA" _
    14. (ByVal lpPathName As String, ByVal bWatchSubtree As _
    15. Long, ByVal dwNotifyFilter As Long) As Long
    16.  
    17. Private Declare Function FindNextChangeNotification _
    18. Lib "kernel32" (ByVal hChangeHandle As Long) As Long
    19.  
    20. Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
    21. Private Const FILE_NOTIFY_CHANGE_LAST_WRITE As Long = &H10
    22. Private Const FILE_NOTIFY_CHANGE_CREATION As Long = &H40
    23.  
    24. Private Sub WaitForFileActivity(ByVal sDirectory As String)
    25. Dim lHandle As Long
    26. Dim lReturn As Long
    27.  
    28. 'if something's written to a file
    29. lHandle = FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_LAST_WRITE)
    30. 'if a file is being created
    31. 'or FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_CREATION)
    32. 'or FindFirstChangeNotification(sDirectory, 0&, FILE_NOTIFY_CHANGE_FILE_NAME)
    33. Do
    34. lReturn = WaitForSingleObject(lHandle, 1)
    35. Call FindNextChangeNotification(lHandle)
    36. DoEvents
    37. Loop While lReturn <> 0
    38. End Sub
    39.  
    40. Private Sub Command1_Click()
    41. WaitForFileActivity "C:\"
    42. MsgBox "Change", vbSystemModal
    43. End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    80

    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
  •  



Featured


Click Here to Expand Forum to Full Width