Jump to content
Sign in to follow this  
asgarcymed

From FileGetShortcut - How to get the target path without exe.exe?

Recommended Posts

asgarcymed

Using:

$lnk_details = FileGetShortcut(@DesktopDir & "\Internet Explorer.lnk" )

MsgBox(0, "", "Target Path: " & $lnk_details[0])

The Message Box will display "C:\Program Files\Internet Explorer\IEXPLORER.EXE"

Next, I would like to put in clipboard the target path without exe.exe (in these example would be "C:\Program Files\Internet Explorer"). How to do this?

Thanks in advance.

Best regards.


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites
SmOke_N

Look at _PathSplit() in the help file.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
asgarcymed

Thank you for your tip! Here it is a good script: :)

#include <file.au3>
#include <array.au3>
$title = "Choose .lnk file"
$lnk_file = FileOpenDialog($title, @DesktopDir & "\", "Shortcuts (*.lnk)")
If @error Then
    MsgBox(0,"","No file was chosen")
EndIf
$lnk_file_details = FileGetShortcut ($lnk_file)
MsgBox(0, "", "Target Path: " & Chr(13) & $lnk_file_details[0])
MsgBox(0, "", "Description: " & Chr(13) & $lnk_file_details[3])
Dim $szDrive, $szDir, $szFName, $szExt
$target_path_array_dir = _PathSplit ($lnk_file_details[0], $szDrive, $szDir, $szFName, $szExt)
$target_path_array_dir_ok = StringTrimRight (_ArrayToString ($target_path_array_dir, "", 1, 2), 1)
ClipPut($target_path_array_dir_ok)

MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites
BrettF

He should have called it as an array...

$lnk_details = FileGetShortcut(@DesktopDir & "\Internet Explorer.lnk" )
MsgBox(0, "", "Target Path: " & StringTrimRight($lnk_details[0],4))

Share this post


Link to post
Share on other sites
smashly

He should have called it as an array...

$lnk_details = FileGetShortcut(@DesktopDir & "\Internet Explorer.lnk" )
MsgBox(0, "", "Target Path: " & StringTrimRight($lnk_details[0],4))
Nope that doesn't trim the file name to leave just the path.. it only trims the file ext from the path :)

so

$lnk_details = FileGetShortcut(@DesktopDir & "\Internet Explorer.lnk" )
MsgBox(0, "", "Target Path: " & StringLeft($lnk_details[0], StringInStr($lnk_details[0], "\", 0, -1) - 1))
seems more appropriate unless your using _PathSplit() which works great ;) Edited by smashly

Share this post


Link to post
Share on other sites
BrettF

Nope that doesn't trim the file name to leave just the path.. it only trims the file ext from the path :)

so

$lnk_details = FileGetShortcut(@DesktopDir & "\Internet Explorer.lnk" )
MsgBox(0, "", "Target Path: " & StringLeft($lnk_details[0], StringInStr($lnk_details[0], "\", 0, -1) - 1))
seems more appropriate unless your using _PathSplit() which works great ;)
I didn't read the OP's question, I just fixed enaimans' code.

Share this post


Link to post
Share on other sites
enaiman

That doesn't work for me

It doesn't work for me either because when I open my Desktop folder I don't see a shortcut for IE (and IT IS there) - I only tried to offer an alternative to OP.

Nope that doesn't trim the file name to leave just the path.. it only trims the file ext from the path

OP said:

Next, I would like to put in clipboard the target path without exe.exe (in these example would be "C:\Program Files\Internet Explorer")

@Bert

Thanks :) I haven't looked at FileGetShortcut description (assumed the OP got it right)

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
asgarcymed

ClipPut(StringLeft($lnk_details[0], StringInStr($lnk_details[0], "\", 0, -1) - 1))oÝ÷ Øb±¨(¡Ö¥µêçjدzÚºÚ"µÍ[H ÌÍÜÞ]K  ÌÍÜÞ    ÌÍÜÞ[YK ÌÍÜÞ^ÌÍÝÙ]Ü]Ø^WÙHÔ]Ü]
    ÌÍÛ×Ù[WÙ]Z[ÖÌK  ÌÍÜÞ]K  ÌÍÜÞ    ÌÍÜÞ[YK ÌÍÜÞ^
BÌÍÝÙ]Ü]Ø^WÙÛÚÈHÝ[Õ[TYÚ
Ð^UÔÝ[È
    ÌÍÝÙ]Ü]Ø^WÙ  ][ÝÉ][ÝËKKJBÛ]
    ÌÍÝÙ]Ü]Ø^WÙÛÚÊ

More easy, less code, less includes...

Thank you!


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites
smashly

Your Welcome :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×