Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Finding the target of a symlink

If you have a question or need help, this is the place to be.
Post Reply
avalonai2
Posts: 5
Joined: Sat Jul 23, 2011 2:23 pm

Finding the target of a symlink

Post by avalonai2 »

I feel like I jumped into the deep end of the pool and forgot my floaties! I am new to python and trying my best to drive to insanity.
I am trying to get the target of a symbolic link when it's created. I tried a bunch of things that's only confused me more. :shock:

OSE did show me the target path but I have an interface for selecting files and haven't figured out how to get the path from it without bringing up
the explorer. HELP!!!!!

Pako? Bueller? Anyone... Anyone??

Thanks :mrgreen:
avalonai2
Posts: 5
Joined: Sat Jul 23, 2011 2:23 pm

Re: Finding the target of a symlink

Post by avalonai2 »

WooHoo! please excuse my underwhelmingness but I was able to get to the link target using this code:

Code: Select all

import sys
import win32com.client 

shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut("d:\\test\\thetarget.lnk")
print(shortcut.Targetpath)
That gets me the Path, now I need to get the actual filename.

Anyone know how? :?:
kenvinlee89
Posts: 1
Joined: Tue Aug 02, 2011 2:07 am

Re: Finding the target of a symlink

Post by kenvinlee89 »

Thanks you for the post.
Hi guys, Im a newbie. Nice to join this forum.
avalonai2
Posts: 5
Joined: Sat Jul 23, 2011 2:23 pm

Re: Finding the target of a symlink

Post by avalonai2 »

No problem, I am a NOOB myself. EG is great and has my imiginaaaaaaation well past overdrive gett'n in to kickbutt, excuse me, I meant kickmybutt territory.
There are EG and python elites in the building, so this is the place to be while on the path, pun intended, to unleashing the might and power of, cue music, Event Ghost.

Enjoy...

I am getting closer, but being a py noobie I am still trying to find how to pick out the target filename.
avalonai2
Posts: 5
Joined: Sat Jul 23, 2011 2:23 pm

Re: Finding the target of a symlink

Post by avalonai2 »

Well talk about feeling silly. I just found out that the code I posted actually returns the target filename of the shortcut when the shortcut isn't screwd up. :oops:

So I threw in a little

Code: Select all

os.path.basename(shortcut.Targetpath)
and there it was the filename.

Eh, I'm a noob nothing lost but my sanity. :mrgreen:
Post Reply