One of the computers went down in puff of smoke and I have connected the HD to a USB adapter to extract all the user data.

The USB drive show up as Drive G: but all symbolic links points to the original drive C: so when I copy all files and follow the symbolic links, I end up copying data from my own drive C:

Is there a command (or way) to change all symbolic links to another drive? Example, changing symbolic link C:\Users\Administrator\fileX.y to point to G:\Users\Administrator\fileX.y instead?

  • No. You can replace the symbolic links one by one, but I would just backup the files of the original C drive, and let the copy not follow the symbolic links. – LPChip Oct 1 '18 at 16:08
  • Just to clarify: your data resides on drive G. You are copying this data to drive C. There are symbolic links that point to drive C, and you want them to work properly after the copy job. Is this the situation, or are you copying the data to a 3rd drive? – sippybear Oct 1 '18 at 20:25

I don't think one can modify a symbolic link, only recreate it. This will require writing a script or program to scan the disk and recreate the symbolic links.

Here is an idea which might be simpler : Create a virtual machine and set this physical drive G: as its C: disk.

Both VMware and VirtualBox support physical/raw disks :

  • Well, I'm quite skilled in the Win32 API using C/C++ and I also had the idea of writing a small program doing this. I just hoped there would be a tool out there to do it. – Max Kielland Oct 1 '18 at 19:52
  • Unfortunately I don't know of any such tool. I also like programming, but in your case I would try the VM solution, for one reason : it cannot destroy the disk because of any bug of mine. In any case, I would counsel making an image backup of the disk and if possible use it instead. – harrymc Oct 1 '18 at 19:57

Instead of trying to modify all your links, you can use robocopy from a command prompt to copy the symbolic link instead of its target.

ROBOCOPY source\path destination\path /E /SL

This command will recursively copy all directories and files from your source to your destination (/E) and instead of copying the target of your symbolic link, it will copy the link itself (/SL)

You can list all your symbolic links and targets with powershell. This answer on StackExchange shows you how.

dir 'Path\to\examine' -Recurse -Force | ?{$_.LinkType} | Select FullName,LinkType,Target

You can overwrite existing links also using powershell.

New-Item -ItemType SymbolicLink -Path "Symbolic\Link\Path" -Target "New\Target\For\Link" -Force

So a script to mod all the links in a folder would look like this:

$directory = 'Path\to\your\links'
$links = dir '$directory' -Force | ?{$_.LinkType}
foreach ($link in $links)  
    $target = $link.Target.Replace('C:\','G:\')
    $path = $link.FullName
    New-Item -ItemType SymbolicLink -Path "$path" -Target "$target" -Force
dir '$directory' -Force | ?{$_.LinkType} | Format-Table FullName,Target

Be sure to modify the $directory value and run this from an admin powershell prompt. You can add the -Recurse flag to the dir command to look in subfolders as well.

  • Yes, but I need to copy the symbolic link target as well since the original drive will be destroyed later. – Max Kielland Oct 1 '18 at 17:09
  • @MaxKielland Does the data that the symbolic links point to exist on the same drive as the symbolic links or are they somewhere else? – sippybear Oct 1 '18 at 17:50
  • Yes, the target of all symbolic link is the same physical partition (as C: whne it was used), but in my system, as an USB drive it is on G: but all symbolic links still points to C: (not realitve links, but absolute links). – Max Kielland Oct 1 '18 at 19:50
  • @MaxKielland Please let me know if that script works out. – sippybear Oct 2 '18 at 17:37

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.