eryksun added the comment:
Here's a rewrite with a cleaner while loop, at least to me:
def list_volumes():
vname = ctypes.create_unicode_buffer(wintypes.MAX_PATH)
vhandle = kernel32.FindFirstVolumeW(vname, len(vname))
if vhandle == INVALID_HANDLE_VALUE:
raise ctypes.WinError(ctypes.get_last_error())
volumes = [vname.value]
try:
while kernel32.FindNextVolumeW(vhandle, vname, len(vname)):
volumes.append(vname.value)
last_error = ctypes.get_last_error()
if last_error != ERROR_NO_MORE_FILES:
raise ctypes.WinError(last_error)
finally:
if not kernel32.FindVolumeClose(vhandle):
raise ctypes.WinError(ctypes.get_last_error())
return volumes
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25241>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com