get properties of links on Windows
Mike C. Fletcher
mcfletch at rogers.com
Fri May 23 11:00:55 EDT 2003
This is an old module, but should still work I'd imagine:
# link.py
# From a demo by Mark Hammond, corrupted by Mike Fletcher
from win32com.shell import shell
import pythoncom, os
class PyShortcut:
def __init__( self ):
self._base = pythoncom.CoCreateInstance(
shell.CLSID_ShellLink, None,
pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
)
def load( self, filename ):
# Get an IPersist interface
# which allows save/restore of object to/from files
self._base.QueryInterface( pythoncom.IID_IPersistFile ).Load(
filename )
def save( self, filename ):
self._base.QueryInterface( pythoncom.IID_IPersistFile ).Save(
filename, 0 )
def __getattr__( self, name ):
if name != "_base":
return getattr( self._base, name )
if __name__=='__main__':
import sys
file = sys.argv[1]
shortcut = PyShortcut()
if os.path.exists( file ):
# load and dump info from file...
shortcut.load( file )
# now print data...
print 'Shortcut in file %s to
file:\n\t%s\nArguments:\n\t%s\nDescription:\n\t%s\nWorking
Directory:\n\t%s\nItemIDs:\n\t<skipped>'%(
file,
shortcut.GetPath(shell.SLGP_SHORTPATH)[0],
shortcut.GetArguments(),
shortcut.GetDescription(),
shortcut.GetWorkingDirectory(),
#shortcut.GetIDList(),
)
else:
# create the shortcut using rest of args...
data = map( None, sys.argv[2:], ("SetPath", "SetArguments",
"SetDescription", "SetWorkingDirectory") )
for value, function in data:
if value and function:
# call function on each non-null value
getattr( shortcut, function)( value )
shortcut.save( file )
HTH,
Mike
Frederik wrote:
>Hi,
>
>is it possible to get the filename on that a link on Windows is pointing to?
>
>thanks,
>
>Frederik
>
>
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
More information about the Python-list
mailing list