Win32 drive mapping... aka "net use"

Lucas Machado LMachado1 at gmail.com
Sat Mar 5 14:45:35 EST 2005


Roger Upole wrote:
> You could use win32api.GetLogicalDriveStrings to list
> the drive letters currently in use, and find the next free
> letter.  net use * probably does something like that under
> the covers.

I went and took your advice and this is where I am now:

>>> import win32api
>>> a = win32api.GetLogicalDriveStrings()
>>> a
'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00'
>>> print a
A:\ C:\ D:\ E:\ Z:\

So I think this function will work great since it gives me a string
that i can simply strip away what i don't need and then split it into a
list and traverse the list.  However, when I try to split it, the
following occurs:

>>> b = a.strip(r'\\\x00')
>>> b
'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00'
>>> b = a.split(r'\\\x00')
>>> b
['A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00']

I'm a bit of a novice at python (even more so of the win32 api), but
I've used the split and strip functions before (for example to get rid
of '\n' from strings) so it is unclear to me why this does not work.

Thanks
--LM




More information about the Python-list mailing list