Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey there I am puzzled as how to go about's monitoring multiple or all hard drives on my computer with filesystem watcher eg. C:\, D:\, E:\ ect..

I wish to be able to monitor all drives and their subfolders excluding CD\DVD drives if they are not ready or no disk is inserted.

I have found some examples online but it has only been confusing as they are not complete in their explanation about how to detect all hard drives and then to assign the paths to multiple instances of the filesystem watcher so that the entire computer is being monitored and not just one directory at a time.


thank you in advance!!
Posted

1 solution

To list the drives you can use DriveInfo.GetDrives Method[^]. For each drive you need to check whether it's local or not. For this the DriveInfo has DriveType[^].

When looping through the drives you can create a new filesystemwatcher and to store the created instances globally, you could for example use a static class with a list poperty. Something like

C#
public static WatchInfo {
   public static List<fileSystemWatcher> Watchers = new List<fileSystemWatcher>();
}

Now when creating the instances, just add them to the list and you can refer them from your program later.

Of course you would need also to set proper event handlers for changes in the drives.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900