Hack Forums
[.NET] File System Watcher - All Drives - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] File System Watcher - All Drives (/showthread.php?tid=4732048)

Pages: Pages 1 2


File System Watcher - All Drives - Only3 - Mar 15, 2015

😅 Title

[Image: 2740a36aeddd78704f6bae1d3d0ecc70.png]

😉


* - SIM-1984933 - Mar 15, 2015

why do that? when you can simply have a button with a text box like so

filedialog.ShowDialog()
TextBox1.Text = fd.SelectedPath
fsw.Path = TextBox1.Text
FileSysWatcher.Path = TextBox1.Text

Private Sub rn(ByVal obj As Object, ByVal z As System.IO.FileSystemEventArgs) Handles fsw.Renamed
ListBox1.Items.Add(z.FullPath)
End Sub

then it will get the correct path & drive
and if even you can just do
Dim MainDrive As String = Mid(Environment.GetFolderPath(Environment.SpecialFolder.System), 1, 3)

im just gonna rel my full project


* - Streetlight. - Mar 15, 2015

Why do you always take pictures? You can literally do
Code
hi
and save time.


* - SIM-1984933 - Mar 15, 2015

FileWatchDog Project Source https://hackforums.net/showthread.php?tid=4732349


* - Trebax. - Mar 15, 2015

He posts pictures so skids don't c&p his code.


* - SIM-1984933 - Mar 15, 2015

(Mar 15, 2015 03:52 PM)TrebaxCoder Wrote:  He posts pictures so skids don't c&p his code.
im talking about the way he did it :~


* - 0xDEAD10CC - Mar 15, 2015

(Mar 15, 2015 03:19 PM)| Hex | Wrote:  why do that? when you can simply have a button with a text box like so

filedialog.ShowDialog()
TextBox1.Text = fd.SelectedPath
fsw.Path = TextBox1.Text
FileSysWatcher.Path = TextBox1.Text

Private Sub rn(ByVal obj As Object, ByVal z As System.IO.FileSystemEventArgs) Handles fsw.Renamed
ListBox1.Items.Add(z.FullPath)
End Sub

then it will get the correct path & drive
and if even you can just do
Dim MainDrive As String = Mid(Environment.GetFolderPath(Environment.SpecialFolder.System), 1, 3)

im just gonna rel my full project

Code
TextBox1.Text = fd.SelectedPath
fsw.Path = TextBox1.Text
FileSysWatcher.Path = TextBox1.Text

^^
If you have the data that populates the Text property for the TextBox control, you should never be using the Text property itself to populate string data for other things. What if you changed the Text to something else? Without reviewing your code it would populate the other string variables with bad data. This is basic fundamental design principles that programmers should follow IMO.

Why? Because Textboxes are used for display. If you decide that you want some kind of formatting with the string data, it'll corrupt whatever else is attempting to parse the data from the control. Display and Data sources should never be mixed/confused.


* - Only3 - Mar 15, 2015

(Mar 15, 2015 04:08 PM)| Hex | Wrote:  im talking about the way he did it :~

u should read the title and the code again 😊


* - SIM-1984933 - Mar 15, 2015

(Mar 15, 2015 05:48 PM)Only3 Wrote:  u should read the title and the code again 😊
well ill just leave this here https://hackforums.net/showthread.php?tid=4732349


* - Only3 - Mar 15, 2015

(Mar 15, 2015 03:24 PM)| Hex | Wrote:  FileWatchDog Project Source https://hackforums.net/showthread.php?tid=4732349
(Mar 15, 2015 05:56 PM)| Hex | Wrote:  well ill just leave this here https://hackforums.net/showthread.php?tid=4732349

🤣 again wow did u decide to speard it all over the net section


* - CodeAssassin - Mar 15, 2015

Lol you never even renamed the variables i used.....

https://hackforums.net/showthread.php?tid=4728497&pid=45221164#pid45221164

...


* - Only3 - Mar 15, 2015

(Mar 15, 2015 06:41 PM)sweetysuckscock Wrote:  Lol you never even renamed the variables i used.....

https://hackforums.net/showthread.php?tid=4728497&pid=45221164#pid45221164

...

why i should i post the right way of doing it 😊 what u want credit for the vars name 🤦‍♂


* - CodeAssassin - Mar 15, 2015

(Mar 15, 2015 06:49 PM)Only3 Wrote:  why i should i post the right way of doing it 😊 what u want credit for the vars name 🤦‍♂

dude you took the code improved it a little and gave no credits you sir are a skid...

w/e just letting everyone else know what your like is all, least i never HAD to copy a? :D ...


* - Only3 - Mar 15, 2015

(Mar 15, 2015 06:55 PM)sweetysuckscock Wrote:  dude you took the code improved it a little and gave no credits you sir are a skid...

w/e just letting everyone else know what your like is all, least i never HAD to copy a? :D ...

let me help u 🤣 ur code is buggy and will not work did u even test it 😏

Code
Imports System.IO

Public Class Form1

    Dim Watchers() As FileSystemWatcher

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      GetDrives()
    End Sub

    Private Sub GetDrives()
      Dim Count As Integer = 0
      Dim drives() As String = Environment.GetLogicalDrives
      ReDim Watchers(drives.Length)
      For i = 0 To drives.Length - 1
      Dim watcher As New FileSystemWatcher(drives(i))
      With watcher
      .Path = drives(i)
      AddHandler .Changed, AddressOf FileSysWatcher_Changed
      AddHandler .Created, AddressOf FileSysWatcher_Created
      AddHandler .Deleted, AddressOf FileSysWatcher_Deleted
      AddHandler .Disposed, AddressOf FileSysWatcher_Disposed
      AddHandler .Error, AddressOf FileSysWatcher_Error
      AddHandler .Renamed, AddressOf FileSysWatcher_Renamed
      End With
      Watchers(i) = watcher
      watcher.IncludeSubdirectories = True
      watcher.EnableRaisingEvents = True
      Next
      TextBox1.AppendText("added all locical drives")
    End Sub

    Private Sub FileSysWatcher_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
      Debug.Print("Name: {0}, Path: {1}", e.Name, e.FullPath)
      TextBox1.Invoke(New MethodInvoker(Sub() TextBox1.AppendText(vbNewLine & String.Format("Name: {0}, Path: {1}", e.Name, e.FullPath))))
    End Sub

    Private Sub FileSysWatcher_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
      Debug.Print("Name: {0}, Path: {1}", e.Name, e.FullPath)
      TextBox1.Invoke(New MethodInvoker(Sub() TextBox1.AppendText(vbNewLine & String.Format("Name: {0}, Path: {1}", e.Name, e.FullPath))))
    End Sub

    Private Sub FileSysWatcher_Deleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
      Debug.Print("Name: {0}, Path: {1}", e.Name, e.FullPath)
      TextBox1.Invoke(New MethodInvoker(Sub() TextBox1.AppendText(vbNewLine & String.Format("Name: {0}, Path: {1}", e.Name, e.FullPath))))
    End Sub

    Private Sub FileSysWatcher_Disposed(ByVal sender As Object, ByVal e As System.EventArgs)
      Debug.Print(e.ToString)
    End Sub

    Private Sub FileSysWatcher_Error(ByVal sender As Object, ByVal e As System.IO.ErrorEventArgs)
      Debug.Print(e.GetException.Message)
    End Sub

    Private Sub FileSysWatcher_Renamed(ByVal sender As Object, ByVal e As System.IO.RenamedEventArgs)
      Debug.Print("Name: {0}, Path: {1}", e.Name, e.FullPath)
      TextBox1.Invoke(New MethodInvoker(Sub() TextBox1.AppendText(vbNewLine & String.Format("Name: {0}, Path: {1}", e.Name, e.FullPath))))
    End Sub

End Class



* - CodeAssassin - Mar 15, 2015

(Mar 15, 2015 07:03 PM)Only3 Wrote:  let me help u 🤣 ur code is buggy and will not work did u even test it 😏

Code
Imports System.IO

Public Class Form1

    Dim Watchers() As FileSystemWatcher

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      GetDrives()
    End Sub

    Private Sub GetDrives()
      Dim Count As Integer = 0
      Dim drives() As String = Environment.GetLogicalDrives
      ReDim Watchers(drives.Length)
      For i = 0 To drives.Length - 1
      Dim watcher As New FileSystemWatcher(drives(i))
      With watcher
      .Path = drives(i)
      AddHandler .Changed, AddressOf FileSysWatcher_Changed
      AddHandler .Created, AddressOf FileSysWatcher_Created
      AddHandler .Deleted, AddressOf FileSysWatcher_Deleted
      AddHandler .Disposed, AddressOf FileSysWatcher_Disposed
      AddHandler .Error, AddressOf FileSysWatcher_Error
      AddHandler .Renamed, AddressOf FileSysWatcher_Renamed
      End With
      Watchers(i) = watcher
      watcher.IncludeSubdirectories = True
      watcher.EnableRaisingEvents = True
      Next
      TextBox1.AppendText("added all locical drives")
    End Sub

    Private Sub FileSysWatcher_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
      Debug.Print("Name: {0}, Path: {1}", e.Name, e.FullPath)
      TextBox1.Invoke(New MethodInvoker(Sub() TextBox1.AppendText(vbNewLine & String.Format("Name: {0}, Path: {1}", e.Name, e.FullPath))))
    End Sub

    Private Sub FileSysWatcher_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
      Debug.Print("Name: {0}, Path: {1}", e.Name, e.FullPath)
      TextBox1.Invoke(New MethodInvoker(Sub() TextBox1.AppendText(vbNewLine & String.Format("Name: {0}, Path: {1}", e.Name, e.FullPath))))
    End Sub

    Private Sub FileSysWatcher_Deleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
      Debug.Print("Name: {0}, Path: {1}", e.Name, e.FullPath)
      TextBox1.Invoke(New MethodInvoker(Sub() TextBox1.AppendText(vbNewLine & String.Format("Name: {0}, Path: {1}", e.Name, e.FullPath))))
    End Sub

    Private Sub FileSysWatcher_Disposed(ByVal sender As Object, ByVal e As System.EventArgs)
      Debug.Print(e.ToString)
    End Sub

    Private Sub FileSysWatcher_Error(ByVal sender As Object, ByVal e As System.IO.ErrorEventArgs)
      Debug.Print(e.GetException.Message)
    End Sub

    Private Sub FileSysWatcher_Renamed(ByVal sender As Object, ByVal e As System.IO.RenamedEventArgs)
      Debug.Print("Name: {0}, Path: {1}", e.Name, e.FullPath)
      TextBox1.Invoke(New MethodInvoker(Sub() TextBox1.AppendText(vbNewLine & String.Format("Name: {0}, Path: {1}", e.Name, e.FullPath))))
    End Sub

End Class

yes it was working thanks :3

What i see is you moved 3 lines and changed another 4 or 5 LOL...