Problem with os.listdir and delay with unreachable network drives on Windows
rroberts at adobe.com
Mon Dec 27 20:07:44 CET 2004
Thank you for your response - this was very helpful.
I find that 'win32net.NetGetUseInfo()' does not
deal with UNC names - it seems to require a drive
specification in the form of a single letter.
The following sequence worked well for me,
resulting in a much shorter 'hang time' for
unreachable network mapped drives than simply
# get list of logical drive strginsdrive strings
volumeList = win32api.GetLogicalDriveStrings().split("\000")[:-1]
# some time later...
# vol is an entry in the volumeList.
dirList = 
if win32file.DRIVE_REMOTE = win32file.GetDriveType(driveLetter):
driveStatus = win32net.NetUseGetInfo(None, driveLetter, 3)
if driveStatus['status'] == 0:
dirList = os.listdir(vol)
# tell user the selected drive is not available.
# tell user the selected drive is not available
# happens when drive letter is not one
# of the current logical drives
>From: Andrey Ivanov <ai2... at yandex.ru> - Find messages by this author
>Date: Thu, 23 Dec 2004 11:44:17 +0300
>Local: Thurs, Dec 23 2004 12:44 am
> Subject: Re: Problem with os.listdir and delay
>with unreachable network drives on Windows
>Reply | Reply to Author | Forward | Print |
>Individual Message | Show original | Report Abuse
>- Show quoted text -
>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.
More information about the Python-list