Problem with os.listdir and delay with unreachable network drives on Windows

Andrey Ivanov ai2009 at yandex.ru
Thu Dec 23 09:44:17 CET 2004


[Read Roberts]
> I wrote my own directory browser in order to get around a bug where 
> tkFileDialog.askdirectory()  can't handle non-ascii paths. However, I
> have a problem where I call os.listdir() on a  mapped network drive,
> e.g. os.listdir("Z:\\"), and if the network drive is unavailable, the
> UI hangs  until the OS returns with an exception because the network
> shared drive is unavailable.

>   I would like to work around this by simply not looking into  mapped
> drives that are not currently mounted.  Is there some way to check 
> the status of mapped drive to see if it is currently mounted, or a 
> better solution? ( I use the call win32api.GetLogicalDriveStrings() 
> to get the list of available drives).

> Also, is there any way to enumerate remote volumes that are mounted 
> by not mapped? I can't easily find this in the win32 stuff or via 
> googling. The win32net calls to enumerate servers and shares sound 
> likely, but don't show such volumes on my system, although I may not
> be using the right arguments.

> I have the current Windows binary install of Python 2.3.4 on my 
> Windows XP system.

Maybe  a  win32net.WNetGetUniversalName()  [expands drive to UNC name]
and   win32net.NetGetUseInfo()  [returns  various  info  on  UNC  name
including  status] will help you. I don't have a time to setup shares,
so I can't guarantee that this approach will work as you expect. First
function  might  raise an exception on disconnected devices, which you
will  need  to handle. You might also need win32file.GetDriveType() to
distinguish between remote and local drives.

-- 
Andrey




More information about the Python-list mailing list