Getting Filename and not only the directory from FileSystemEventArgs

NJDubois

Well-known member
Joined
May 15, 2008
Messages
84
Programming Experience
Beginner
I've been trying to get the download settings for different browsers, and in my research found some code that watches the file system for changes. Perfect! But I cannot get the filename, its always the directory.

All the help I am reading says that e.name should work, but it again, only returns the directory.

Here is the code I am working with :

VB.NET:
Imports System.IO
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim watcher As New FileSystemWatcher
        watcher.Path = Me.TextBox1.Text
        watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName)

        AddHandler watcher.Changed, AddressOf OnChanged
        AddHandler watcher.Created, AddressOf OnChanged
        AddHandler watcher.Deleted, AddressOf OnChanged
        AddHandler watcher.Renamed, AddressOf OnRenamed


        watcher.EnableRaisingEvents = True
    End Sub

    Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
        MsgBox("File: " & e.Name & " " & e.ChangeType)
    End Sub


    Sub OnRenamed(ByVal source As Object, ByVal e As FileSystemEventArgs)

    End Sub

   
End Class

I cannot for the life of me figure out how to get the actual file name? Its always the path, minus the filename.

Any help is greatly appreciated. This solved a major problem for me!!

Thanks
Nick
 
Yes, I know that it was supposed to, but the problem was that it wasn't. All I ever got was the directory.

I have solved the problem.

using :

watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.Attributes
watchfolder.IncludeSubdirectories = True

I understand now. I was just watching C:\, because I do not know the download path of Chrome, Firefox or Internet Explorer, I had to use C:\.

Because I was not telling it to watch sub directories, It would only tell me that hey, this directory changed. But it didn't know the filename. Setting includesubdir to true fixed my problem!

Finally!

lol

Thanks anyways
Nick
 
Back
Top