faqts : Computers : Programming : Languages : Python : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

44 of 46 people (96%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How can I enumerate drives (local and network) in Python?

Jul 12th, 2000 00:36
unknown unknown, richard_chamberlain


On Win32 you can use:
import win32api,string
drives=win32api.GetLogicalDriveStrings()
drives=string.splitfields(drives,'\000')
print drives
GetLogicalDriveStrings returns a string with each drive null terminated 
so you can use the string module to separate them into a list.
There is also a win32api.GetLogicalDrives() which returns a bitmask 
where each bit represents a drive letter, so 1101 (or 13 in decimal) 
would represent (going from right to left) a:\,c:\ and d:\.