I looked over the inetrnet but found nothing about this so I ask here - Is it possible to create a shortcut of a file and put it in a specific directory of my choose with python? For example, I have a folder named "EXAMPLE" in ' C: ' . I want to create automatically a shortcut of Google Chrome and put it in this folder. Is it possible to do so using python(and not just dragging it over by myself)? Thanks
Asked
Active
Viewed 7,683 times
3
-
which os are you using? – zom-pro Aug 22 '15 at 10:03
1 Answers
4
I assume because of you mention C: that you're using windows. So you can use winshell
import os, winshell
from win32com.client import Dispatch
desktop = winshell.desktop()
path = os.path.join(desktop, "Media Player Classic.lnk")
target = r"P:\Media\Media Player Classic\mplayerc.exe"
wDir = r"P:\Media\Media Player Classic"
icon = r"P:\Media\Media Player Classic\mplayerc.exe"
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = wDir
shortcut.IconLocation = icon
shortcut.save()
For more info look at here
If you're on a unix-based system you can use the symbolic link command.
zom-pro
- 1,421
- 2
- 16
- 32
-
Thanks! In addition, is it possible to check if the shortcut is already exsits before creating a new one? So that there will be only 1 shortcut and not more than 1 for the same file..? – ErezProductions Aug 22 '15 at 10:10
-
It's just a file so you can do it like this: http://stackoverflow.com/questions/82831/check-whether-a-file-exists-using-python – zom-pro Aug 22 '15 at 10:11