Sign in to follow this  
Followers 0
mihok

Shortcut to a Folder

14 posts in this topic

Clearly you can use FileCreateShortcut to create a shortcut to a file, but how do I create a shortcut to a folder? FileCreateShortcut does not seem to work for this. Thank you in advance for any help.

Share this post


Link to post
Share on other sites



Have you tried just setting the folder as the target?

Share this post


Link to post
Share on other sites

Have you tried just setting the folder as the target?

Yes and while the function creates a shortcut, since it is treated as a file, if you double-click the shortcut, it pops up a dialog asking you which program you would like to use to open the file instead of showing the contents of the folder in an explorer window.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I'm guessing your target file wasn't set correctly. This is my code, on my desktop I have an au3 folder that I am creating the shortcut to... works fine.

Double check if your using a macro (like @DesktopDir) I always forget to add a \ when needed.

FileCreateShortcut(@DesktopDir & "\au3", @DesktopDir & "\shortcut to directory")

Oh and welcome to the forum.

Edited by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

I'm guessing your target file wasn't set correctly. This is my code, on my desktop I have an au3 folder that I am creating the shortcut to... works fine.

Double check if your using a macro (like @DesktopDir) I always forget to add a \ when needed.

FileCreateShortcut(@DesktopDir & "\au3", @DesktopDir & "\shortcut to directory")

Oh and welcome to the forum.

Thank you for the welcome and the help. I appreciate both. As for the problem I'm having, I'm sure I'm doing something dumb, but I don't think it's to the wrong target. If I right click on the shortcut and select properties, the "Target type" is "File Folder", the "Target location" has the right parent directory, and if I copy the entry "Target" and paste it into Microsoft Explorer (minus the quotation marks), Explorer opens the right directory. Do you have any ideas as to why the shortcut won't do the same? Thanks again for the help.

Share this post


Link to post
Share on other sites

Does Windows give you an error of any type?

Share this post


Link to post
Share on other sites

Does Windows give you an error of any type?

No, it just gives me the "Open With" dialog when I try to access the shortcut...no errors, though.

Share this post


Link to post
Share on other sites

No, it just gives me the "Open With" dialog when I try to access the shortcut...no errors, though.

Just to test this out to see if everyone is getting the same thing I am, I created a simple example that is a stub of my original script. On the desktop, create a folder with the name "Parent." In Parent, create two folders, one named "1" and the other named "a." In "1," create a folder named "2" and in "a" create a folder named "b." Now, in "2," create a script that has only the following line and run it:

FileCreateShortcut(@ScriptDir & "\..\..\a\b\", @DesktopDir & "\b.lnk")

When I run the script, a shortcut named "b.lnk" is created, but when I try to open it, the "Open with" dialog appears.

Suggestions or comments on my stupidity?

Share this post


Link to post
Share on other sites

No, it just gives me the "Open With" dialog when I try to access the shortcut...no errors, though.

If you examine the properties, delete the leading and trailing quotation marks then close the properties window does it work?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

If you examine the properties, delete the leading and trailing quotation marks then close the properties window does it work?

Indeed it does! Any ideas on how to prevent the quotation marks from being added by the script?

Share this post


Link to post
Share on other sites

Indeed it does! Any ideas on how to prevent the quotation marks from being added by the script?

Hopefully, this will close the loop on this. As discovered in previous posts, the reason that the shortcut was not working was the presence of the quotation marks, not the location of the target. After testing, I figured out that the quotation marks were added because of the presence of using relative directions (such as "/../..") in the path. That is why it worked for others, but not for my case. While the FileCreateShortcut function properly handles the relative addressing to create the proper path, in doing so, it adds in the quotation marks. I'm not sure if that's a feature or a bug. Regardless, if you handle the relative addressing yourself, then everything works fine. Using the example from above of the Parent, a, b, 1, and 2 directories, the following code is an example of how to deal with the relative addressing. I'm sure there's a fancier way to do it, but this worked for me.

$path = @ScriptDir & "\..\..\a\b"

$upDirIndx = StringInStr($path, "\..")
While $upDirIndx > 0
    $beginningIndx = 1
    $lastSlashIndx = 1
    While $lastSlashIndx > 0
        $lastSlashIndx = StringInStr(StringMid($path, $beginningIndx, $upDirIndx - $beginningIndx), "\")
        If $lastSlashIndx > 0 Then
            $beginningIndx += $lastSlashIndx
        EndIf
    WEnd

    $path = StringTrimRight($path, StringLen($path) - $beginningIndx + 1) & StringTrimLeft($path, $upDirIndx + 3)
    $upDirIndx = StringInStr($path, "\..")
WEnd

FileCreateShortcut($path, @DesktopDir & "\b.lnk")

I'm interested in if anyone has comments on what I did. Thanks to those that helped.

Share this post


Link to post
Share on other sites

Just call FileGetLongName(@ScriptDir & "\..\..\a\b") and then use that as your target. That should help you.

Share this post


Link to post
Share on other sites

Just call FileGetLongName(@ScriptDir & "\..\..\a\b") and then use that as your target. That should help you.

It worked if you do FileGetLongName(@ScriptDir & "\..\..\a\b", 1), but not if you leave out the second argument. Strangely, both ways produce identical targets (with quotation marks), but putting in the second argument works while omitting it does not. I don't understand that at all. It works, though. I appreciate your help.

Share this post


Link to post
Share on other sites

You're welcome. I don't really use the function, so I didn't think of the second argument.

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  
Followers 0