76

I have a folder scheme like (highly simplified version):

New Files
 >Tools
 >Scripts
Tested Files
 >Tools
 >Scripts

... and I'd like to have a shortcut in each folder from the "New Files" child folders, to the "Tested Files" child folder. But this folder may be moved around from time to time, which would break said shortcuts.

Is there a way to make a relative shortcut to each folder? I remember doing this in HTML where you could set a path, something along the lines of .../Files to go back to a parent and then into a new folder, but I'm unsure if this is something support under Windows shortcuts?

PS: The case of similarly relative shortcuts, when the target is a file, is dealt with in https://stackoverflow.com/questions/1169556/making-a-windows-shortcut-start-relative-to-where-the-folder-is. In the present case the target is a Folder.

7
  • 1
    Did you try ../Files, with two dots? I'm not running Windows but I think it may work.
    – Brian Z
    Sep 12, 2013 at 14:53
  • 1
    @sancho.s - AFAIK, the answers there only work for executing .bat files. What's needed here is a way to refer to a folder instead. Dec 18, 2017 at 21:19
  • @ToolmakerSteve - I guess you checked / read "the answers there" only superficially. One of them (stackoverflow.com/a/1751350/2707864) is the accepted solution here, that one being ca. 4 years older. I did not try it. Another one (stackoverflow.com/a/29261618/2707864) is the second half of the accepted solution here. You even commented on that one. I tried it and it works. It is not necessary to be thorough to place a comment, but one should try not to mislead readers. Dec 19, 2017 at 10:17
  • 1
    @sancho.s - Actually, I read those answers in detail. However, I misunderstood Relative when I followed the link to its description. [this was before I read Rik's answer] I guess I was confused by the fact that those answers all boiled down to using features to execute code (since that Q was about executing). You providing the link to that set of answers, with no further clarification, increased my confusion, rather than leading me closer to a solution. Now that you have specified what in all those answers was relevant, it is helpful. Thank you. Dec 22, 2017 at 1:23

8 Answers 8

73

You can use this utility: Relative.

It basically creates a shortcut to explorer.exe with the parameter of your relative path with a right click (same way as you create a normal shortcut).

Of course you can do this manually.
In your example you would create a shortcut in "New Files\Tools" to

%windir%\explorer.exe "..\..\Tested Files\Tools"

You can use the usual context-menu "New/Create shortcut" of Windows for this and typing above command in "Type the location of the item"-box.

11
  • 1
    I did read about that during my previous research, but i was hoping for a native solution within Explorer. This will be my backup plan though, cheers. Sep 12, 2013 at 15:13
  • By the way, will this relative path stay the same between systems also? Or will i need Relative to be installed if i move the folders/contents between different systems? Sep 12, 2013 at 15:16
  • 3
    "Relative" only makes the shortcut using the standard "%windir%\explorer.exe" so you don't need Relative on the different system. It would be the same as typing %windir%\explorer.exe before the relative path while making a standard shortcut. So if you do this manually you won't need Relative at all. (You just need to remember the command before your relative path)
    – Rik
    Sep 12, 2013 at 16:16
  • 4
    The manual solution here does not work for me out of the box. In addition, I have to change "Start In" from %windir% to empty.
    – notan3xit
    Dec 1, 2017 at 8:48
  • 4
    is there a solution to use the same explorer window where the shortcut file is opened? using this solution opens a new explorer window. i currently need a shortcut file with relative path that when opened, it still uses the same explorer window.
    – acegs
    Oct 26, 2019 at 1:39
48

One possible solution is use a one line batch file instead of a short cut to open whatever you wanted to open. The batch file will let you use relative paths inside itself and will have a working directory of whatever folder the batch file is placed in.


Another option is have your shortcut start cmd.exe instead with whatever you are launching then pass whatever it is you are launching in as a argument to cmd.exe

enter image description here

%COMSPEC% is a environment variable points to the command prompt by default.

/C causes the console to close itself after it executes the command.

4
  • 3
    Useful for a different situation, however the question isn't about opening some file; it is about being able to jump to a specified folder within Windows Explorer. Is there a way to adapt this answer to do so? Dec 18, 2017 at 21:22
  • 1
    But this answer still matches to the title of the question. That's why I came here. To create a relative link to a (exe) file. This solution works, but the /C does not make the console to close itself in my case.
    – MA-Maddin
    Nov 11, 2020 at 16:50
  • 1
    This is a fantastic solution to replicate explorer GUI behavior. Typically running explorer.exe "SomeFolder" twice would open two instances of that folder, but this solution fixes it. It also fixes the problem of minimizing if maximized and maximizing if minimized that happens if using start "" "SomeFolder" (although that does fix the problem of opening multiple folder windows).
    – bat_cmd
    Mar 25, 2022 at 7:29
  • This is amazing, thanks so much. Pinning the "application" even works! I just wish I knew about this years ago! Best!!! Now does anyone know how to reference the icon relative? Lol.
    – jacktrader
    Jan 8 at 17:12
15

This trick works :

%COMSPEC% /C start "your exe name without path"

example

%COMSPEC% /C start winmine.exe

9
  • 5
    Please read the question again carefully. Your answer does not answer the original question.
    – DavidPostill
    Aug 18, 2016 at 17:37
  • 2
    For Win10 1607, this solution answers the OP's question perfectly, Target: %COMSPEC% /C "start GoogleChromePortable.exe -enableextensions -incognito" Start In: [leave blank]
    – semtex41
    Feb 4, 2017 at 5:42
  • 2
    @semtex41 Huh? I try that, and the result is an error dialog saying "Windows cannot find 'GoogleChromePortable'. What does that have to do with OP's goal of navigating Windows Explorer to a specified folder? Dec 18, 2017 at 21:27
  • 4
    @semtex41- OP's stated goal is ".. a shortcut .. to the "Tested Files" child folder". If you aren't explaining how to have this answer accomplish that, then please clarify what you were adding to the answer. It looks like you just gave another example of how to execute a .exe file. But the answer already showed such an example. So please re-state the point you were making? Dec 18, 2017 at 21:55
  • 2
    Your answer aims to the case where the target is an executable file. The OP is interested in shortcuts to folders. Please check if your answer addresses the case, and post an explicit example for that. Dec 19, 2017 at 10:10
8

I'm using similar solution in a template that runs my web development environment (open project directory, open browser, run WAMP, run SCSS...)

enter image description here

I can pass arguments to my bat script and etc., this is cool. Make sure to put /c argument after cmd.exe

8

You can use mklink. It allows you to create symbolic links, hard links and directory links.

 mklink /d Tools "..\Tested Files\Tools"  (elevated command prompt)

If there is no elevated access, you can use /j

 mklink /j Tools "..\Tested Files\Tools"

To move around the whole structure you should use the xcopy command. For example, if all the structure is under container:

container
   New Files
      <SYMLINKD> Scripts [..\Tested Files\Scripts]
      <SYMLINKD> Tools  [ ..\Tested Files\Tools]
   Tested Files    
      Scripts
      Tools

entering the command

 xcopy /b /e container container2

will create the following structure:

container2
   New Files
      <SYMLINKD> Scripts [..\Tested Files\Scripts]
      <SYMLINKD> Tools  [ ..\Tested Files\Tools]
   Tested Files    
      Scripts
      Tools

The /b switch will copy the Symbolic links instead of converting them to folders. (Note that /b has a completely different meaning for the copy command)

4
  • 1
    But will that link still be correct, if the set of folders is moved to a different location? Dec 18, 2017 at 21:29
  • This requires privileges I do not have, although it looks like it would do the job... Would you mind posting an image of the resulting Shortcut properties, once it was created? Dec 19, 2017 at 10:28
  • 1
    The links are indeed correct. That can be confirmed with the "dir" command. The problem is that "copy-paste", "move" and "copy" actions of the File Manager will destroy the structure. I have modified the answer to include a workaround.
    – Krauss
    Sep 14, 2018 at 18:53
  • It would also be helpful to add an explicit warning of what exactly will happen if you were to e.g. simply use File Explorer to move or copy the folders, and why that's not desired. May 10, 2021 at 17:46
3

A shortcut can record it's location in a variable and call a command using the variable. For example, create the shortcut "Grandparent" with target:

%windir%\system32\cmd.exe /c set HERE="%CD%" && "C:\Here.bat"

Create the batch file "C:\Here.bat" with the single line:

@%windir%\explorer.exe /n,/select, %HERE%

Now, whatever folder Grandparent is in, when you click it, the parent of its parent folder opens. It even works with Grandparent in a root directory.

Your batch file could have used %HERE% in starting something other than explorer.exe. Or instead of Here.bat after the && in the shortcut target, you could call a program that makes use of %HERE%.

On my system Grandparent seems to work with & or &&.

1
  • 1
    && only performs the next call if the previous call did not return an error, while & doesn't care. In this case, there should be no difference.
    – leewz
    Jun 8, 2016 at 2:02
1

If you leave the 'Start In' box empty in the properties of the Shortcut, the links be relative to the current working directory.

See also https://stackoverflow.com/a/17951772/40961

4
  • How does this help OP's goal of navigating Windows Explorer to a specified folder? Dec 18, 2017 at 21:31
  • If you had the problem then the solution makes sense... how does your comment help on every answer? Jan 13, 2018 at 12:51
  • Your assertion that "leav[ing] the 'Start In' box empty... [causes] links [to] be relative to the current working directory" is only correct in the context of an answer like Scott Chamberlain's or Alexis PERROTTEY's, and is completely incorrect in the case of a typical shortcut. May 10, 2021 at 17:58
  • 1
    I use Total Commander, and in my case the "%windir%\explorer.exe" isn't a good solution because if I launch the link I go out of Total Commander, in Explorer. The empty "start in" instead solve this problem in any file manager because the link is followed into the Total Commander panel..
    – Antonio
    Oct 19, 2021 at 13:19
0

You can create an environment variable that contains the (relative) Path to the target folder or a folder above it in the file system structure.

Example:

  • Environment Variable:

    %Dropbox% = "C:\Users\User 1\Dropbox"

  • Shortcut Target:

    "%Dropbox%\Install\Utilities\File.exe"

You can use the DOS command SETX to create environment variables.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .