[python-win32] detect mapped network path

Simon Dahlbacka simon.dahlbacka at gmail.com
Thu Jun 30 11:46:47 CEST 2005


On 6/30/05, Tim Golden <tim.golden at viacom-outdoor.co.uk> wrote:
> [Simon Dahlbacka]
> | I'm having trouble with the fact that
> | win32file.FindFirstChangeNotification seems to not like network paths.
> | (Or at least that is what I concluded after getting the following
> | traceback)
> |
> | Traceback (most recent call last):
> |   File "C:\Python23\lib\threading.py", line 436, in __bootstrap
> |     self.run()
> |   File
> | "c:\GSP\Instr\Common\Utilities\LogBrowser\LogFileReaderThread.py",
> | line 59, in run
> |     False, FILE_NOTIFY_CHANGE_SIZE)
> | error: (1, 'FindFirstChangeNotification', 'Incorrect function.')
> |
> |
> | Now, I what to indicate to the user that this is not possible. A
> | direct UNC path is no problem \\foo\bar\blarg.baz
> |
> | ..but how do i find out if let's say X:\foo\bar\blarg.baz is a local
> | path or in fact a mapped network path?
> 
> I don't quite understand why this is happening, but to
> answer your most direct question, here's a snippet of
> code which may help:
> 
> <code>
> import win32net
> 
> def mapped_drives ():
>   drives = {}
>   resume = 0
>   while 1:
>     (_drives, total, resume) = win32net.NetUseEnum (None, 0, resume)
>     for drive in _drives:
>       if drive['local']:
>         yield drive['local'], drive['remote']
>     if not resume: break
> 
> for letter, mapping in mapped_drives ():
>   if mapping == r"\\voapps\d":
>     print letter
>     break
> </code>

thanks, I tried your code, but it seems win32net.NetUseEnum(None, 0, resume)
just returns ([], 0, 0) all the time !?! ..and thus it does not work.
An ordinary "net use" issued in the cmd window yields the correct
information though.. (they seem to be NetWare Services though, if that
matters?)


/Simon


More information about the Python-win32 mailing list