Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Shortcut - Create with Relative Path


Shortcut - Create with Relative Path

How to Create a Shortcut with a Relative Path
Published by Pyprohly
31 Aug 2016
Published by

How to Create Shortcut with Relative Path

information   Information
Shortcuts are an indisputable necessity of any user-friendly OS, and Windows is no exception. Their lingering existence make them an accustomed part of the Windows experience, providing a effortless means of navigating the file system, or launching our most used programs. They serve to boost user productivity by about 55%, and crowd desktop space by 10%.

The Windows’ Shortcut file, a metadata file that is interpreted by the shell, has adapted to support a number of features such as being able to display a custom icon, assign hotkeys to the link, store compatibility setttings including being able to run the program as administrator, link to web resources (not to be confused with .URL files), reference “magic strings” which allow linking to items inaccessible in the file system, and others. These are the main reasons why symbolic links haven’t yet been a suitable replacement for end-users¹.

Despite the diverse assortment of functionality on offer, Windows Shortcuts’ suffer a major disadvantage in that they are unable to reference a relative target. This means that Shortcut files are incapable of pointing to a file system item that is situated in a known directory relative to the directory in which the link was invoked, consequently preventing their portability.

Luckily, there are some work-arounds and this tutorial outlines a slew of tricks you can use to counter this restrictive limitation on Windows’ part. Users wanting to use shortcuts on portable storage devices will find this tutorial especially handy.
Note   Note
The pros and cons of each of the methods described here are summarised in the below table. Refer to this table before completing an option as you many find some options incapable for your situation. I.e., you would not want to use the Option One if you intent to use the link on a non-NTFS formatted portable storage device (symbolic links are exclusively compatible with NTFS).

 Option OneOption TwoOption ThreeOption Four
Able to display custom icon---
Navigates using current Explorer instance (when linking to a folder)--
Able to pass arguments and/or switches to linked programs--
Able to adjust the working directory--
Is link transparent to applications using the link---



CONTENTS:


Shortcut - Create with Relative Path OPTION ONE Shortcut - Create with Relative Path
Using a Symbolic Link

Note   Note
Note well that symbolic links are a feature of the NTFS file system and Windows will only allow creation of a symbolic link on a NTFS formatted partition. If you wish to use this option on a portable storage device, ensure that it is NTFS formatted first.
warning   Warning
A symbolic link may be moved around in the same partition and while the relative path is applicable, the link will continue to work. However, one should not be tempted at any time to copy a symbolic link anywhere, or move the symbolic link across a partition. In doing so, the symbolic link will be destroyed and the resulting file will be replaced by a copy of the target.
1. Open up an Elevated Command Prompt.

2. Change the working directory to that of the folder in which you would like the link file placed. Enter the cd command as per the syntax below, appropriately replacing <directory path>. The prompt text should change to reflect the new working directory.
Code:
cd /d <directory path>
Shortcut - Create with Relative Path-1.2.gif
3. Do Step 4.a if your target item is a file or program, or do Step 4.b if it is a directory.

4.a Enter the following mklink command to create the link, substituting <link name> with a filename of your choice and specifying a target file or executable for <target>.
Note   Note
The argument <link name> should not match a name that is already taken by a file in the current directory, but <target> may be any path name, whether it actually exists at the time of creation or not.
Code:
mklink "<link name>" "<target>"
Shortcut - Create with Relative Path-1.4..gif
4.b Enter the below command, substituting <link name> with a filename of your choice and specifying a target directory path for <target>.
Note   Note
The note in step 4 applies here as well. The only difference between the command featured here and that seen in step 4 is the addition of the /d switch. For more information about the mklink command enter mklink /? at the command line.
Code:
mklink /d "<link name>" "<target>"
Shortcut - Create with Relative Path-1.4.b.gif



Shortcut - Create with Relative Path OPTION TWO Shortcut - Create with Relative Path
Using a Shortcut of Window Explorer

Note   Note
The Explorer program, located at C:\Windows\Explorer.exe, given any path name as an argument on the command line, will attempt to invoke the given item. Taking advantage of this, we can create an ordinary shortcut of the explorer program and pass any desired path to it and explorer will invoke that item. This path can be relative.
1. Create a new shortcut in any desired location. Right-click in a folder or on the desktop and select New -> Shortcut.

2. Enter the text “explorer” as the location for the item to create a shortcut for (as a shorthand for typing the application’s full path, C:\Windows\explorer.exe).
Shortcut - Create with Relative Path-2.2.gif
3. Enter what ever name you would like for your shortcut to display here, then click Finish.
Shortcut - Create with Relative Path-2.3.gif
4. Right-click the new shortcut file and select Properties.

5. In the Target field, append a space to the existing text and enter the relative (or absolute) path of the folder or file that you wish to link to.
Shortcut - Create with Relative Path-2.5.gif
Tip   Tip
If this path is relative it will be relative to the directory of which the shortcut file itself resides only if the Start in field is empty, else if the Start in field is populated with a valid path name the path here will be used as the base path for the path you’ve entered in the Target field.


6. Remove all text in the Start in field. Alternatively, you may type an absolute path here and this path will be used as the base path for the relative path you’ve entered as an argument in the Target field. You may close the Properties pane now.
Shortcut - Create with Relative Path-2.6.gif
7. Check if your link works. Double-click your new relative shortcut. If your user’s Documents folder opens up instead of the item you intended to link to, the item could not be found and you should check that you’ve completed Steps 5 and 6 correctly.



Shortcut - Create with Relative Path OPTION THREE Shortcut - Create with Relative Path
Using a Batch File

Note   Note
Although flexible and easy to manage this option may not be preferable due to the unsightly quick flash of a command prompt screen each time the link is accessed.
1. Open Windows Notepad or your preferred text editor.

2. Append an “@echo off” line to begin the batch file with.
Shortcut - Create with Relative Path-3.2.gif
3. If you intend to link to an application and wish to artificially alter the working directory for it, add a cd line like below, where <target> is the path of a directory, else skip this step.
Code:
cd /d <target>
4. Follow with a series of start commands, using the syntax presented. <target> may be a directory or file relative path name.
Code:
start "" "%~dp0\<target>"
Tip   Tip
%~dp0 represents the path of the batch file. If you’d like your target to be relative to the root directory instead, remove the %~dp0 part.
Shortcut - Create with Relative Path-3.4.gif
5. Save the file to a location of your choice and give it an extension of .bat.



Shortcut - Create with Relative Path OPTION FOUR Shortcut - Create with Relative Path
Using a Visual Basic Script

Note   Note
This option may feel particularly slow if many Explorer windows are open.
1. Download the VBS_Shortcut.vbs file with the provided link.
VBS_Shortcut.vbs

download
2. Open the downloaded VBScript file with Notepad or your preferred text editor.

3. Locate lines 16 and 17 and adjust the string values appropriately, with “Target” being the relative path of the item you wish to link to and “WorkingDirectory” being the working directory for your application. Leave this value blank if you don’t require the application’s working directory be altered.
Shortcut - Create with Relative Path-4.3.gif




That’s all. Got a question, query, suggestion, or recommendation? Please let me know in the section below right away. Enjoy,
Pyprohly






Comment

 Shortcut - Create with Relative Path




Tutorial Tools Search this Tutorial
Search this Tutorial:

Advanced Search




Similar help and support threads
Windows 7 Tutorial Category
Unable to create shortcuts in startup folder "cannot create shortcut"
I am unable to create a shortcut in the startup folder on my Dell Optiplex 780. Every time I try, I get the following error, "Windows cannot create a shortcut here. Do you want to place the shortcut on the desktop instead?" No I do not want it on the desktop, I want the program to start with...
General Discussion
Custom 'Desktop (create shortcut)' Remove .fileextension - Shortcut
Hi guys n girls, I have for ever got sick and tired of right click -> open Send to Menu and creating a Desktop Shortcut for a file or app....then needing to go to the Desktop right click the newly made shortcut and then removing the trailing file extension, dash and words shortcut in brackets....
Customization
Shortcut problem (relative path)
Hi everyone, Someone know how I could change my shortcut path, regardless of the machine ? My picture is in C:\Users\Manon\Desktop\perso\1.png. I made some research, I have to change the "Start in" in the properties of the shortcut. But what I have to write in ? Thanks for your advices,...
General Discussion
Create shortcut
How do I create a shortcut to my desktop, so that the Windows explorer will open up the selected library in the 'my documents' section? Of course there is no "create shortcut" button when I right click on the library.
General Discussion
How to create Shortcut 'SED' instead of 'SED.exe - Shortcut'?
I often have to create Shortcuts to executable code. I used http://www.sevenforums.com/tutorials/804-shortcut-extension-remove-restore.html to getSED.exe instead of the Win7 default SED.exe - Shortcutas name of the newly created shortcut. But I would prefer to have just 'SED'. Any way to do...
General Discussion
Create a System Image Shortcut - Create
How to Create a "Create a System Image" Shortcut in Windows 7 This will show you how to create a Create a System Image shortcut in Windows 7. To be able to use this shortcut, you must be logged in as an administrator. EXAMPLE: Create a System Image
Tutorials


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 05:24.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App