Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

File System Watcher - All Drives

😅 Title

[Image: 2740a36aeddd78704f6bae1d3d0ecc70.png]

😉
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
Why do you always take pictures? You can literally do
Code
hi
and save time.
FileWatchDog Project Source https://hackforums.net/showthread.php?tid=4732349
He posts pictures so skids don't c&p his code.
[Image: 2wMmsQs.gif]
(Mar 15, 2015 03:52 PM)Trebax. Wrote:  He posts pictures so skids don't c&p his code.
im talking about the way he did it :~
(Mar 15, 2015 03:19 PM)SIM-1984933 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.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Mar 15, 2015 04:08 PM)SIM-1984933 Wrote:  im talking about the way he did it :~

u should read the title and the code again 😊
(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
(Mar 15, 2015 03:24 PM)SIM-1984933 Wrote:  FileWatchDog Project Source https://hackforums.net/showthread.php?tid=4732349
(Mar 15, 2015 05:56 PM)SIM-1984933 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
Lol you never even renamed the variables i used.....

https://hackforums.net/showthread.php?ti...id45221164

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

https://hackforums.net/showthread.php?ti...id45221164

...

why i should i post the right way of doing it 😊 what u want credit for the vars name 🤦‍♂
(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 ...
(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
(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...


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by WeedIsInTheAirSep 23, 2022 03:42 PM 0 173 Sep 23, 2022 03:42 PM
Last Post: WeedIsInTheAir
[Shell] by Emre_Oct 1, 2020 07:14 PM 0 129 Oct 1, 2020 07:14 PM
Last Post: Emre_
[Shell] by Emre_Aug 31, 2019 05:10 AM 0 100 Aug 31, 2019 05:10 AM
Last Post: Emre_