find network drives, win

Bill Bell bill-bell at bill-bell.hamilton.on.ca
Mon Nov 5 13:36:20 EST 2001


stojek at part-gmbh.de (Marcus Stojek) wrote, in part:
> under windows I have to find out for a given path whether 
> the drive is local or a network drive

To find out whether a drive 'X' is local use:

>>> 'X' in filter ( lambda x: exists ( x + ':\\'), uppercase )
0

To find out whether a drive 'X' is on the network:

>>> from win32com.client import Dispatch
>>> network = Dispatch ( 'Wscript.Network' )
>>> networkDrives = network.EnumNetworkDrives ( )

This failed for me just now, presumably because I'm running Win2K 
standalone. So let me simulate what would happen were I 
connected to a network that makes drives available.

>>> networkDrives=[ ( 'M:', '\\SERVER1' ), ( 'N:', '\\SERVER2' ) ]

Assuming this is ok, one can then use

>>> 'X' in map ( lambda x: x[0][0], networkDrives )

Good luck, Marcus.

Bill
"It is the time that you have wasted for your rose that makes your rose so important."--St-Exupery




More information about the Python-list mailing list