ErezProductions
ErezProductions

Reputation: 41

Is it possible to create shortcuts into a specific directory in python?

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

Upvotes: 3

Views: 8741

Answers (1)

zom-pro
zom-pro

Reputation: 1649

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.

Upvotes: 6

Related Questions