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: Any way to reference the current drive, even if its letter changes?

05 Dec 2015   #1
pluviosilla

TX
 
 
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 System SpecsSystem Spec
.
05 Dec 2015   #2
AndreyT

Windows 7 Pro x64
 
 

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 System SpecsSystem Spec
05 Dec 2015   #3
pluviosilla

TX
 
 

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 System SpecsSystem Spec
.

05 Dec 2015   #4
pluviosilla

TX
 
 

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 System SpecsSystem Spec
05 Dec 2015   #5
AndreyT

Windows 7 Pro x64
 
 

Quote   Quote: Originally Posted by pluviosilla View Post
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 System SpecsSystem Spec
05 Dec 2015   #6
pluviosilla

TX
 
 

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 System SpecsSystem Spec
05 Dec 2015   #7
AndreyT

Windows 7 Pro x64
 
 

Quote   Quote: Originally Posted by pluviosilla View Post
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.

Quote   Quote: Originally Posted by pluviosilla View Post
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).

Quote   Quote: Originally Posted by pluviosilla View Post
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 System SpecsSystem Spec
05 Dec 2015   #8
pluviosilla

TX
 
 

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 System SpecsSystem Spec
05 Dec 2015   #9
bigmck

Windows 7 Home Premium 32-Bit - Build 7600 SP1
 
 

My whole life has been symbolic.
My System SpecsSystem Spec
05 Dec 2015   #10
AndreyT

Windows 7 Pro x64
 
 

Quote   Quote: Originally Posted by pluviosilla View Post
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 System SpecsSystem Spec
Reply

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




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
modifying drive letter: Letter to choose not in the list
Hello I had to open my pc and remove drives. Once re-installed, one of the drive has seen it's letter allocation modified. Since 2 application is pointing to G drive, I would like to be able to get it back. Hard disk (2) Was G: Now, show has a D: CD drive was D: Now show has E: G:...
Hardware & Devices
changing one drive letter all 3 partitions change to that drive letter
sir, i have windows 7 desktop. there are some partition on it.but there is problem with these partition. All the three partition have the same drive letter.i attach a link showing the picture. all three partitions are dynamic , simple. if i open these drives only the contents of one drive are...
Hardware & Devices
How do you reset (clear) all current USB drive letter assignments?
How do you reset (clear) all current USB drive letter assignments? As a result of changing my external USB Hub controller from a CyberPower CP-H720P (USB 2.0 7-Port Hub w/Power Adapter) to a SIIG 06-0960A (USB 3.0 w/3-Ports & USB 2.0 w/3-Ports plus Card Reader w/Power Adapter), all of my...
Hardware & Devices
External Hard Drive - Drive Letter changed - unable to change back
I have a USB external hard drive that I keep all my documents etc on (had it for years) I upgraded from Vista Home to & Home Premium then had to upgrade recently to Professional to run my Sage. Through all these upgrades my ext. drive ran fine. Occasionally the drvie letter would change if I...
Hardware & Devices
Want to Assign a drive letter to a partitioned device but the letter i
Want to Assign a drive letter to a partitioned device but the letter is not in the list I created a partitioned drive I went to assign letter G but I don't see it in the list. no drive is using the letter G I do believe that some USB is using letter G, but I don't see my USBs ( see image) ...
General Discussion
Can't change hard drive letter to needed letter
I lost my Event Viewer, and had to do a repair installation to fix it. Unfortunately, during the repair install, Windows decided to rename my second HD as the D: drive... it was K: before that. Now I cannot access any of my docs, pictures, music, or videos through the normal means... they don't...
General Discussion


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 09:39.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App