file system iteration
rtw at freenet.co.uk
Mon Oct 9 16:22:29 CEST 2006
Tim Golden wrote in news:mailman.119.1160403292.11739.python-
list at python.org in comp.lang.python:
>| Searching for a file by name. Scanning for viruses.
>| There are lots
>| of legitimate reason to walk all paths from a centra
>| starting point, no???
> Well, to get you started, I think this is the kind
> of thing you'll want. Uses ctypes, which is built-in
> to Python 2.5 so presumably legit.
> import ctypes
> import string
> GetDriveType = ctypes.windll.kernel32.GetDriveTypeA
> for letter in string.uppercase:
> print letter, "=>", GetDriveType ("%s:" % letter)
> You'll have to refer to
> and various headers to get the values in question, but they
> look quite straightforward at a glance.
These seem to map when tested on my system:
DRIVE_TYPE_MAP = dict( enumerate ( """\
## if you need the constants ...
for i, name in DRIVE_TYPE_MAP.iteritems():
exec( "%s = %d" %( name, i) )
GetDriveTypeW = ctypes.windll.kernel32.GetDriveTypeW
for i in range( ord( 'A' ), 1 + ord('Z') ):
path = u"%c:\\" % chr( i )
print path, DRIVE_TYPE_MAP[ GetDriveTypeW( path ) ]
More information about the Python-list