How do you change a Windows shortcut using Python?
e.g. from:
H:\\My Music\\some_file.mp3
to:
D:\\Users\\Myself\\My
Here's another, more appropriate way to do this in Python with Winshell library: Using Python to create Windows shortcuts. In your case the code will look like:
import os, winshell
from win32com.client import Dispatch
desktop = winshell.desktop()
path = os.path.join(desktop, "some_file.mp3.lnk")
target = r"D:\Users\Myself\My Music\some_file.mp3"
wDir = r"D:\Users\Myself\My Music"
icon = r"D:\Users\Myself\My Music\some_file.mp3"
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = wDir
shortcut.IconLocation = icon
shortcut.save()
Existing shortcut should be deleted or rewritten. If you need it for batch processing of shortcut files then I think there's some way to read paths from existing shortcuts, but didn't managed to find it.