Any way to reference the current drive, even if its letter changes?

Page 1 of 2 12 LastLast

  1. Posts : 8
    TX
       #1

    Any way to reference the current drive, even if its letter changes?


    I would like to create symbolic links and / or shortcuts on a portable drive that remain valid even when the drive letter changes. The links are to folders on the same drive.

    I assume there is no environmental variable like %SystemDrive% that references the current drive. Is there any way to use junction points or soft links to accomplish this?
      My Computer


  2. Posts : 14
    Windows 7 Pro x64
       #2

    Um... In Windows symbolic links support relative paths and a path that begins with `\` references the root folder of the current drive. So, in your case just create a symbolic link that references your desired path, just start that path with `\` (no drive letter). Done.

    I just tried this by creating a root folder `Test` and then creating a symbolic link to `\Test` elsewhere on the same drive. If works fine regardless of the current drive letter.

    Directory junctions do not work that way - they require absolute path beginning with the drive letter. But symbolic links accept relative paths and work perfectly fine in that role.
      My Computer


  3. Posts : 8
    TX
    Thread Starter
       #3

    Interesting suggestion. Certainly worth a try, but I find that I can create the symbolic link without referencing the drive letter, but Windows simply inserts the letter in the Target path. In other words, the "\" is a nice shorthand when running the mklink command but does not get rid of the absolute path, including the drive letter, that is assigned to the link.
      My Computer


  4. Posts : 8
    TX
    Thread Starter
       #4

    BTW, I just discovered that I can edit desktop.ini files to reference folder icons using relative paths. I am hoping I can find a way to create shortcuts or symbolic links using relative paths in a similar manner.
      My Computer


  5. Posts : 14
    Windows 7 Pro x64
       #5

    pluviosilla said:
    Certainly worth a try, but I find that I can create the symbolic link without referencing the drive letter, but Windows simply inserts the letter in the Target path. In other words, the "\" is a nice shorthand when running the mklink command but does not get rid of the absolute path, including the drive letter, that is assigned to the link.
    Interesting. I use Far Manager to create my symbolic links instead of `mklink` command. And Far Manager creates symbolic links with relative paths without any problems at all.

    P.S. I just tried doing this from command line with `mklink` and this command

    Code:
    mklink /D TestLink \Test
    successfully created a symbolic link `TestLink` to directory `\Test` without adding a drive letter.

    However, I tried this on Windows 10. Is Windows 7 different in this regard?

    P.P.S. This post on Superuser suggests that it has always been like that. I don't know why your Windows insists on converting relative path to absolute one. Are you sure you are creating a symbolic link and not a directory junction?
      My Computer


  6. Posts : 8
    TX
    Thread Starter
       #6

    Sorry if I have been unclear. I am not disputing that the command syntax you used works:

    mklink /d testlink \test

    works just fine. But your use of the "\" without the drive letter is little more than a shorthand for running the command.

    After creating your link, look at its properties in Windows Explorer. You will notice that Windows has inserted the drive letter. Furthermore, unlike shortcuts, users are not allowed to edit the Target area of the link.
      My Computer


  7. Posts : 14
    Windows 7 Pro x64
       #7

    pluviosilla said:
    Sorry if I have been unclear. I am not disputing that the command syntax you used works:

    mklink /d testlink \test

    works just fine. But your use of the "\" without the drive letter is little more than a shorthand for running the command.
    Sorry, but that is false. This is not a shorthand. The link will be created specifically with a relative path, exactly as it is specified in the command line (`\test` in this case).

    The ability to use relative paths has been one of the "advertised" features of NTFS symbolic links since the moment of their inception.

    pluviosilla said:
    After creating your link, look at its properties in Windows Explorer. You will notice that Windows has inserted the drive letter.
    No, apparently you got misled by the show that Windows Explorer put up for you. It was Windows Explorer who decided to "decipher" the relative path for you in Properties window in an apparent attempt to be "helpful". The link itself does not physically refer to that drive letter. The link stores only relative path, exactly as you specified it in the command line.

    Just try it: take a USB drive, create a bunch of relative symbolic links on it and then change the drive letter in Disk Management. See if your symbolic links still work (and they will).

    pluviosilla said:
    Furthermore, unlike shortcuts, users are not allowed to edit the Target area of the link.
    Well... that just one of Windows Explorer's shortcomings, no more, no less. Other tools can edit the path in a symbolic link without any problems (Far Manager, again; also Link Shell Extension).
      My Computer


  8. Posts : 8
    TX
    Thread Starter
       #8

    By editing the desktop.ini file I can now make the icons associated with each folder in a portable drive completely independent of the drive letter. You CAN use relative paths for defining the IconResource variable in desktop.ini. This was a very welcome discovery for me, and not many people know this trick, so I was hoping there might be some little-know means of using relative paths with shortcuts and/or symbolic links.

    Everyone uses portable drives now. If there is no way to move a drive around without invalidating all the shortcuts & symbolic links then Windows file system architecture is hopelessly antiquated.
      My Computer


  9. Posts : 4,751
    Windows 7 Home Premium 32-Bit - Build 7600 SP1
       #9

    My whole life has been symbolic. :)
      My Computer


  10. Posts : 14
    Windows 7 Pro x64
       #10

    pluviosilla said:
    Everyone uses portable drives now. If there is no way to move a drive around without invalidating all the shortcuts & symbolic links then Windows file system architecture is hopelessly antiquated.
    Well, if you'll keep stubbornly ignoring the fact that NTFS symbolic links have always been able to use relative paths and that relative paths don't invalidate when you "move the drive around", then of course Windows file system architecture might look antiquited to you. But I'm afraid Windows file system architecture is not to blame here.
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 19:36.
Find Us