[python-win32] detect mapped network path

Tim Golden tim.golden at viacom-outdoor.co.uk
Thu Jun 30 10:56:33 CEST 2005


[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>


TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Python-win32 mailing list