Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1502

[VB6] Event based file system watcher in single self-contained class

$
0
0
This is based on the similarly named System.IO.FileSystemWatcher in .Net Framework. Most of the code is hoisted from a fafalone submission here in these forums.


' cFileSystemWatcher.cls
'=========================================================================
'
' FileSystemWatcher (c) 2023 by wqweto@gmail.com
'
' Based on code by fafalone at https://www.vbforums.com/showthread.php?805991
'
' Uses self-contained and IDE-safe subclassing on API created window
'
' Emulates FileSystemWatcher in System.IO namespace of .Net Framework
'
'=========================================================================

<too big to post>

See link below


Some testing code in a form for a sample of usage:


Option Explicit

Private WithEvents
m_oWatcher As cFileSystemWatcher

Private Sub Form_Load()
___
Set m_oWatcher = New cFileSystemWatcher
___m_oWatcher
.Path = "D:\TEMP"
___
m_oWatcher.IncludeSubdirectories = True
___
m_oWatcher.EnableRaisingEvents = True
End Sub

Private Sub
Command1_Click()
___
Dim eType ______As UcsWatcherChangeTypesBitmask
___
Dim sName ______As String
___
___
eType = ucsWctAll
___
If m_oWatcher.WaitForChanged(eType, sName, Timeout:=10000) Then
_______Debug
.Print "WaitForChanged, eType=" & eType & ", sName=" & sName, Timer
___
End If
End Sub

Private Sub
m_oWatcher_OnChanged(ByVal ChangeType As UcsWatcherChangeTypesBitmask, FullPath As String, Name As String)
___
Debug.Print "OnChanged, ChangeType=" & ChangeType & ", FullPath=" & FullPath & ", Name=" & Name, Timer
End Sub

Private Sub
m_oWatcher_OnCreated(ByVal ChangeType As UcsWatcherChangeTypesBitmask, FullPath As String, Name As String)
___
Debug.Print "OnCreated, ChangeType=" & ChangeType & ", FullPath=" & FullPath & ", Name=" & Name, Timer
End Sub

Private Sub
m_oWatcher_OnDeleted(ByVal ChangeType As UcsWatcherChangeTypesBitmask, FullPath As String, Name As String)
___
Debug.Print "OnDeleted, ChangeType=" & ChangeType & ", FullPath=" & FullPath & ", Name=" & Name, Timer
End Sub

Private Sub
m_oWatcher_OnRenamed(ByVal ChangeType As UcsWatcherChangeTypesBitmask, FullPath As String, Name As String, OldFullPath As String, OldName As String)
___
Debug.Print "OnRenamed, ChangeType=" & ChangeType & ", FullPath=" & FullPath & ", Name=" & Name & ", OldFullPath=" & OldFullPath & ", OldName=" & OldName, Timer
End Sub


Full working project: FileSystemWatcher2.zip

cheers,
</wqw>

Viewing all articles
Browse latest Browse all 1502

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>