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
, 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.
Linked PRs
gh-102519: Add os.listdrives, os.listvolumes and os.listmounts on Windows #102544
gh-102519: Add doc updates for os.listdrives, listvolumes and listmounts #102585
gh-102519: Avoid failing tests due to inaccessible volumes #102706