|
-
September 29th, 2018, 02:52 PM
#1
FileSystemWatcher .Path string
Hi, I've been trying to find out why a path string is not being accepted as a valid path to set up a FileSystemWatcher in some code, and haven't found any solution as to what format it needs to be in. Here's my code:
Code:
Dim plnPair(1) As String
Public Sub SetupFileWatcher(fswBase As String, fswTarget As String, fswFilter As String, SyncObject As Form)
If fswBase.Length = 0 Then
Return
End If
plnPair(0) = fswBase
plnPair(1) = fswTarget
For Each plnPath As String In plnPair
Me.BeginInit()
Me.SynchronizingObject = SyncObject
Me.InternalBufferSize = 32768
Me.IncludeSubdirectories = True
Me.Filter = fswFilter
Me.Path = plnPath
Me.NotifyFilter = NotifyFilters.FileName Or NotifyFilters.CreationTime
AddHandler Me.Created, New FileSystemEventHandler(AddressOf Me.OnCreated)
AddHandler Me.Deleted, New FileSystemEventHandler(AddressOf Me.OnDeleted)
Me.EnableRaisingEvents = True
Me.EndInit()
MessageBox.Show(plnPath)
Next
End Sub
The code is executing, because the MessageBox shows the paths that are being set up, but the FileSystemWatcher is not starting as expected. I found that if I insert the string value in the path statement manually, it sets up as expected; for instance, when I write:
Code:
Me.Path = "c:\users\user\Pictures\Camera Roll"
This sets up the watcher as it should. But if I use the variable plnPath as it is in my code, it doesn't set up, as if the format is not being read as a string. I tried:
Code:
Me.Path = CType(plnPath, String)
This didn't get the desired result either. So I'm not sure what the issue is, and if anyone can suggest how I may be making a mistake, let me know. Thanks....
Tags for this Thread
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
|