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

.NET 

Using filesystemWatcher

Hello Guys...

Code
'class Variables....
Dim usb As String = My.Computer.FileSystem.SpecialDirectories.ToString
  Dim Alldrives() As String = IO.Directory.GetLogicalDrives


Private Sub FileSystemWatcher1_Changed(sender As Object, e As FileSystemEventArgs) Handles fsw.Deleted

        Dim deletedfile As String

        For Each Me.usb In Alldrives
            Try

                fsw.Path = usb
                deletedfile = "File-" & e.FullPath.ToString
                MessageBox.Show(deletedfile)

            Catch ex As Exception

            End Try
        Next


I was writing some code to watch all the drives in a system..if any of the file is deleted it pop a message and show deleted file path..
The code compiles just fine.
But there is some problem with the code ..it not giving expected output.
Please somebody help me with editing the code so that it works perfectly...
A little explanation will also be very helpful..

Thanks in Advance.
(Mar 13, 2015 10:06 AM)sweetysuckscock Wrote:  
Code
Private Sub FileSystemWatcher1_Renamed(ByVal sender As Object, ByVal e As System.IO.RenamedEventArgs) Handles FileSystemWatcher1.Renamed, FilesystemWatcher2.Renamed, Filesystemwatcher3.renamed

Can i use filesystemwatcher with removable drives...
if so could u suggest me how to do that..

if not suggest me the best way to monitor all the drives in a system ,including removable drives at the same time..

ThanK You
Quote:The GetDrives() method will pick up any thumb drives etc.


Hi....
Thank you very much for the help..Its a great post...

I tried your code...it runs successfully ,but still there is a problem...it cant watch removable drives....
And the following lines hard for me to understand..could you explain a little bit for me..

Code
For i = 0 To drives.Length - 1
      Dim watcher As New FileSystemWatcher(drives(i))
      With watcher
      .Path = drives(i)

      Watchers(i) = watcher

      watcher.EnableRaisingEvents = True

Whats this Watchers(i) = watcher for??
drives(i) returns all drives including removable...But drives(i)=Removable drive not working in FileSystem Watcher...??

Once Again Thank You very much for the help..🤝
Quote: I have no idea what your doing i tested the code just and it picks up all my thumb drives, so not sure what your doing???


I run you code without any edit on my system...But dont know why its not picking up any removable drives...

Any idea????

Watchers(i)=watcher-----> I mean whats the purpose of this line ...i tried to run without these line...the program run fine without these lines...

Thank You[/quote]

Do you not see the For loop?

I think you really need to go over the basics as your missing really simple stuff here mate.

but just so you know so it add the current "watcher(drive letter)" to the array so you could access it later if needed.
[/quote]

Their is no problem with your code...but the culprit here is the Dvd Drive....it will give some problem...all the drives after the dvd drive in Alldrives array wont work...
I finally got it fixed...Add try/Catch... ✌
no this is not solve the problem i told him that his code buggy and not working
https://hackforums.net/showthread.php?tid=4732048


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by FluffyMcFluffSep 17, 2015 11:00 AM 2 127 Sep 17, 2015 11:00 AM
Last Post: FluffyMcFluff
[C#] by severosSep 11, 2015 04:03 PM 3 178 Sep 11, 2015 04:03 PM
Last Post: Nikey646
[.NET] by Prototype7434Mar 15, 2015 06:35 AM 3 113 Mar 15, 2015 06:35 AM
Last Post: Prototype7434