[python-win32] os.popen/winpipe

Tim Golden tim.golden at viacom-outdoor.co.uk
Thu Nov 18 18:14:05 CET 2004


[Jürgen Kareta]

[Tim Golden]
| > I realise that you're probably just using these
| > snippets as examples of using popen etc. But, just
| > in case these are real examples, you can achieve the
| > first one by using os.listdir / glob.glob and the
| > second by using win32net.NetUseAdd
| > 
| > Just in case...
| 
| Yeah, it's in case... . I'm really new to win32api and like 
| to hear helpful 
| hints. 

The first one's easy:
(and, before anyone else chips in, there are of course
several ways to skin this cat. I'm just going for initial
simplicity.)

<code>
import os

for filename in os.listdir ("."):
  if filename.startswith ("ch"):
    print filename
</code>

NET USE is a bit more messy. You'll need to read up on the
way in which this works, but the following works:

<code>
import win32net

drives = {}
resume = 0
while 1:
  (_drives, total, resume) = win32net.NetUseEnum (None, 0, resume)
  for drive in _drives:
    if drive['local']:
      drives[drive['local']] = drive['remote']
  if not resume: break

for k, v in drives.items (): print k, "=>", v</code>
</code>

and to map a drive / printer, something like this:

<code>
import win32net

#
# The local / remote items could just as well
#  be LPT2: and \\printserver\printer
#
win32net.NetUseAdd (
  None,
  0,
  {
    'local' : "K:",
    'remote' : r"\\tdi_nt4a\user"
  }
)
</code>

Happy Pythoning on win32!

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