List of disk drives on Windows?

Mensanator mensanator at aol.com
Tue May 20 15:45:29 EDT 2008


On May 20, 2:18 pm, Bob Greschke <b... at passcal.nmt.edu> wrote:
> This MUST have been asked before, but I can't seem to Google the right
> thing.  How can I get a list of drives on a Windows box, like ["C:\",
> "D:\"], like I can if I do something like listdir("/Volumes") on a Mac?
>
> Thanks!
>
> Bob

>>> import os.path

>>> dl = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

>>> drives = ['%s:' % d for d in dl if os.path.exists('%s:' % d)]
>>> drives
['C:', 'D:', 'F:', 'G:', 'H:', 'I:', 'J:', 'M:', 'N:', 'O:', 'P:',
'Q:', 'R:', 'S:', 'T:', 'U:', 'X:', 'Y:']




More information about the Python-list mailing list