Is there a Rust function or module for iterating over all the removable drives attached to a Windows machine?

Viewed 401

Is there a Rust module or crate that provides a way to iterate over the removable drives that are attached to a Windows machine? I am running an embedded version of Windows 7 x64. The drives I want to detect are USB-connected flash-drives.

I am primarily a C# developer with C/C++ experience in the distant past, and am new to Rust and it is still seeming a bit opaque to me, so sorry for the newbie question. I am not seeing this in the Crates.io nor in the std::fs module.

I need something such as a vector of the attached removable drives (or a vector of objects each of which represents a drive plus some way to get the properties of that drive, specifically it's drive-letter and whether it is removable).

Thank you in advance for your time and help!

1 Answers

There are some crates available that helps you to achieve this issue and mentioned in comments like followings:

If you do not want to depend on third party crates, you can make a call to windows itself and run the following call and get the output of it:

wmic logicaldisk where drivetype=2 get deviceid, volumename, description

You can make a windows command call via this reference

Also this Question can be helpful.

Related