[Tutor] Python on Windows: any way to access shortcut's info?

Terry Carroll carroll at tjc.com
Mon Jan 9 00:19:17 CET 2006

I would like to know the name of the shortcut (link, I think, in Unix
parlance) from which a python program is being invoked.  I'd also like to
be able to access the directory where the shortcut lives.

Toy example: here's a directory structure:


arga.py contains:

  import sys,os
  print "ARGS:", sys.argv
  print "WD:", os.getcwd()
  raw_input()  # just to keep the window open

argb.py and argc.py are both shortcuts to arga.py

When I run arga.py (e.g., by double-clicking on it, I get, as expected:

ARGS: ['C:\\test\\argtest\\arga.py']
WD: C:\test\argtest

When I run argb.py, I get the same thing.  I'd hoped (but didn't really
expect) sys.argv would be ['C:\\test\\argtest\\argb.py'] .

When I run argc.py, same thing.  In this case, I'd hoped sys.argv would be 
['C:\\test\\argtest\\testdir\\argc.py']; and os.getcwd() would have given 
back 'C:\test\argtest\testdir'.

Why do I care?

Well, I'd like to set up a directory where the shortcut and all its 
files will live.  I'd hoped keying off of the shortcut name might be an 
easy way to do this.

I suspect I'm out of luck: my guess is that windows does all the lookup of 
what the shortcut points to, and then launches the file pointed to; and by 
the time Python gets control, the shortcut information is long gone.  
Anyone know for sure?

More information about the Tutor mailing list