简体   繁体   中英

How can I detect a file on a USB connected to a Raspberry Pi running Windows 10 IoT Core? (C# UWP)

I am trying to dynamically enumerate the drive letters of USBs as they are connected to my Raspberry Pi running Windows 10 IoT Core.

It is my understanding that I can use Windows.Devices.Enumeration.DeviceWatcher or DeviceWatcherTrigger to do this. Once a USB is detected I also want to be able to see if it is empty or, if it isn't, scan for whether it contains a file in a specified directory.

Any help would be greatly appreciated.

Yes, use Windows.Devices.Enumeration.DeviceWatcher to enumerate the portable storage devices on-the-fly, just listen to the Added/Removed/Updated event of DeviceWatcher shall be good enough.

A good tip is if you want to listen to the event in the background(aka, when the foreground app is suspended, you need to handle the Added/Removed/Updated event in a separate windows runtime component, and register the background watcher with Add/Remove/Update event triggers.

Refer to the DeviceEnumerationAndPairing demo project on github for code samples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM