From: Armin Zingler on
Am 09.03.2010 17:09, schrieb Mike Beebe:
> moFolderSysWatch = New FileSystemWatcher(m_WatchDirectory, "")

Drop the 2nd arg. No file matches "". Dropping it means "*.*" which fits all.

And, if you want to monitor changes of a directory name, you must monitor
it's _parent_ folder.

> m_WatchDirectory = m_WatchDirectory.Substring(0, _
> m_WatchDirectory.LastIndexOf("\"))
> m_WatchDirectory &= "\Files"

IO.Path.Get* and IO.Path.Combine are helpful.

--
Armin
From: Mike Beebe on
Changing the following made it work. BTW, OnRenamed and
moFileSysWatch_Renamed both execute.

moFolderSysWatch = New System.IO.FileSystemWatcher()


moFolderSysWatch = New System.IO.FileSystemWatcher()
moFolderSysWatch.Path = m_WatchDirectory
moFolderSysWatch.IncludeSubdirectories = True
'moFolderSysWatch.NotifyFilter = NotifyFilters.DirectoryName
moFolderSysWatch.NotifyFilter = IO.NotifyFilters.DirectoryName
AddHandler moFolderSysWatch.Renamed, AddressOf OnRenamed
moFolderSysWatch.EnableRaisingEvents = True


"Mike Beebe" wrote:

> Sorry, that should have been RenamedFolderHandler. The corrected code is
> below.
>
>
> Imports System.IO
> Imports System.Threading
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
>
>
> #Region " Windows Form Designer generated code "
> #End Region
>
> Private m_WatchDirectory As String
> Private WithEvents moFolderSysWatch As FileSystemWatcher
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>
> m_WatchDirectory = Application.StartupPath
> m_WatchDirectory = m_WatchDirectory.Substring(0, _
> m_WatchDirectory.LastIndexOf("\"))
> m_WatchDirectory &= "\Files"
>
> moFolderSysWatch = New FileSystemWatcher(m_WatchDirectory, "")
> moFolderSysWatch.IncludeSubdirectories = True
> moFolderSysWatch.NotifyFilter = NotifyFilters.DirectoryName
> moFolderSysWatch.EnableRaisingEvents = True
> End Sub
>
> Private Sub moFolderSysWatch_Renamed(ByVal sender As Object, ByVal e As
> System.IO.RenamedEventArgs) Handles moFolderSysWatch.Renamed
> Debug.Print("moFolderSysWatch_Renamed")
> RenamedFolder(e)
> End Sub
>
> Private Sub RenamedFolder(ByVal e As System.IO.RenamedEventArgs)
> 'Needed for cross-thread calls
> If Me.InvokeRequired Then 'are we running on a secondary thread
> Dim d As New RenamedFolderDelegate(AddressOf RenamedFolderHandler)
> Me.Invoke(d, New Object() {e})
> Else
> RenamedFolderHandler(e)
> End If
> End Sub
>
> 'Needed for cross-thread calls
> Private Delegate Sub RenamedFolderDelegate(ByVal e As
> System.IO.RenamedEventArgs)
>
> Private Sub RenamedFolderHandler(ByVal e As System.IO.RenamedEventArgs)
> lstFiles.Items.Add(Now.ToString() & " Renamed '" & e.OldFullPath & _
> "' to '" & e.FullPath & "'")
> End Sub
>
> End Class
>
>
>
> "Armin Zingler" wrote:
>
> > Am 09.03.2010 15:11, schrieb Mike Beebe:
> > > Dim d As New RenamedFolderDelegate(AddressOf RenamedFileHandler)
> >
> >
> > I don't find "RenamedFileHandler".
> >
> >
> > --
> > Armin
> > .
> >
From: Mike Beebe on


"Armin Zingler" wrote:

> Am 09.03.2010 17:09, schrieb Mike Beebe:
> > moFolderSysWatch = New FileSystemWatcher(m_WatchDirectory, "")
>
> Drop the 2nd arg. No file matches "". Dropping it means "*.*" which fits all.
>
> And, if you want to monitor changes of a directory name, you must monitor
> it's _parent_ folder.
>
> > m_WatchDirectory = m_WatchDirectory.Substring(0, _
> > m_WatchDirectory.LastIndexOf("\"))
> > m_WatchDirectory &= "\Files"
>
> IO.Path.Get* and IO.Path.Combine are helpful.
>
> --
> Armin
> .
>
From: Mike Beebe on
Thanks Armin.

How can I tell if e.FullPath is a file or folder? File do NOT have to have
a file extension.

"Armin Zingler" wrote:

> Am 09.03.2010 17:09, schrieb Mike Beebe:
> > moFolderSysWatch = New FileSystemWatcher(m_WatchDirectory, "")
>
> Drop the 2nd arg. No file matches "". Dropping it means "*.*" which fits all.
>
> And, if you want to monitor changes of a directory name, you must monitor
> it's _parent_ folder.
>
> > m_WatchDirectory = m_WatchDirectory.Substring(0, _
> > m_WatchDirectory.LastIndexOf("\"))
> > m_WatchDirectory &= "\Files"
>
> IO.Path.Get* and IO.Path.Combine are helpful.
>
> --
> Armin
> .
>
From: Armin Zingler on
Am 10.03.2010 18:17, schrieb Mike Beebe:
> Thanks Armin.
>
> How can I tell if e.FullPath is a file or folder? File do NOT have to have
> a file extension.

Right, and directories can have an extension.


Dim IsDirectory = IO.Directory.Exists(e.FullPath)


--
Armin
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Border style of panel.
Next: creating new component class.