Python Glossary Русский

Python 3.12+Windowsosfunction

os.listvolumes()

os — file system

Returns the list of volumes in the system as GUID paths; use os.listmounts() to get their mount points. Windows only, Python 3.12+.

Syntax

os.listvolumes()

It returns volumes, not drives: the list may include hidden partitions with no letter, such as a recovery partition. Translate them via os.listmounts before showing users. If you only need the familiar drive letters, os.listdrives is simpler.

Examples

import os
print(not hasattr(os, 'listvolumes') or callable(os.listvolumes))   # → True
print('listvolumes' in dir(os) or os.name != 'nt')   # → True
vols = os.listvolumes() if hasattr(os, 'listvolumes') else []
print(isinstance(vols, list))   # → True
print(all(isinstance(v, str) for v in vols))   # → True

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy