Add os.listdrives
on Windows · Issue #102519 · python/cpython (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
We don't currently have a way to get all the root directories on Windows, since os.listdir('/')
doesn't contain everything.
I propose a very simple API:
>>> os.listdrives()
["C:\\", "D:\\", ...]
>>> os.listdrives(uuids=True)
["\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}\", ...]
Basically, listdrives(uuids=True)
would return everything found by FindNextVolume, while listdrives()
would apply GetVolumePathNamesForVolumeName to each GUID and return all of those. (This may return the same volume multiple times under different names, which is fine - os.stat
can be used to see if they're the same st_dev
.)
There's an endless amount of variations we could also apply here, but the most important functionality in my mind is to expose the OS API. App developers at least then have a starting point to do whatever they may need.