dump_link.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # dump_link.py - dumps information about shell shortcuts
  2. #
  3. import sys, os
  4. from win32com.shell import shell, shellcon
  5. import pythoncom
  6. import glob
  7. from win32com.storagecon import *
  8. def DumpLink(fname):
  9. shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
  10. persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
  11. persistFile.Load(fname,STGM_READ)
  12. shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
  13. fname, findData = shellLink.GetPath(0)
  14. print("Filename:", fname, ", UNC=", shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0])
  15. print("Description:", shellLink.GetDescription())
  16. print("Working Directory:", shellLink.GetWorkingDirectory())
  17. print("Icon:", shellLink.GetIconLocation())
  18. def FavDumper(nothing, path, names):
  19. # called by os.path.walk
  20. for name in names:
  21. print(name, end=' ')
  22. try:
  23. DumpLink(name)
  24. except pythoncom.com_error:
  25. print(" - not a link")
  26. def DumpFavorites():
  27. favfold = str(shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_FAVORITES))
  28. print("Your favourites are at", favfold)
  29. os.path.walk(favfold, FavDumper, None)
  30. if __name__=='__main__':
  31. if len(sys.argv)>1:
  32. for fspec in sys.argv[1:]:
  33. files = glob.glob(fspec)
  34. if files:
  35. for file in files:
  36. print(file)
  37. DumpLink(file)
  38. print()
  39. else:
  40. print("Can not find", fspec)
  41. else:
  42. print("Dumping your favorites folder!")
  43. DumpFavorites()