31

Is it possible to copy a Symlink to a directory in Windows 7. When I try to copy a symlink'd directory, it tries to deep copy the contents to the location.

8 Answers 8

29

I don't know of a way to do it within Windows Explorer, but you can use xcopy at the command line with the /b argument, see here.

1
  • 1
    @Neal Worked for me like a charm. I have added /i as well. Make sure you are working with folder SYMLINKS (not junctions). Mar 9, 2017 at 15:31
22

use the following command in the elevated command prompt:

xcopy /b /i <source symlink name> <destination symlink name>

The output is 0 File(s) copied nevertheless the symlink is created in the destination. This is tested under Windows 7 and Windows 8.x but should work starting as of Vista

UPDATE: it works in Windows 10 as well

5
  • 2
    doesn't work for me, it still does a physical copy, not copying a symlink...
    – jakub.g
    Aug 4, 2016 at 15:55
  • 1
    Worked for me: Win 10 x64, elevated prompt. Tested on win 2012 R2 as well. MAKE SURE YOU DO NOT MIX JUNCTIONS WITH SYMLINKS. Mar 9, 2017 at 15:34
  • Not working on Windows 10.2004. Elevated prompt. 0 files copied and that's what it did.
    – ygoe
    Aug 13, 2020 at 18:24
  • Worked for me! xcopy /b /i *.yaml C:\destination\folder (In explorer they are indeed type .symlink, e.g. file.yaml.symlink) Even said 6 files copied. Mar 17, 2021 at 18:25
  • My source symbolic link was on another server and it gave the error, "File not found. 0 files copied" but still seemed to work. Aug 25, 2021 at 15:53
11

Use a program that supports them, obviously. Far Manager for example allows me to either copy symlinks as links or traverse them and copy their contents:

alt text

1
  • Correction, it does work for local symlinked folders only. For network ones only xcopy /b /i helps. Mar 9, 2017 at 15:45
2

You can use Link Shell Extension for this, however the instructions are a bit convoluted. (for copying already-existing symbolic-links)

Instructions

  1. Use its LSEConfig.exe utility to change the "Outer Junction/Symbolic Link" setting to "Splice".
  2. Right-click and "Pick Link Source" the parent folder of the sym-linked folder you want to copy.
  3. Go to the parent folder of the place you want to drop the sym-linked folder, and run "Drop As: Smart Copy".
  4. Rename the temporary parent "container folder" to the destination/real parent-folder name.

The procedure is somewhat of a hassle, so I'd recommend using xcopy or Far Manager instead. (haven't tried them yet, but I'm assuming they're more straight-forward for direct/single sym-linked-folder copying)

(Link Shell Extension is still worth getting, in my opinion, for the streamlined creation of sym-links, however.)

2

Far Manager was the only thing that worked. Thanks Joey.

For some reason Link Shell Extension either doesn't provide a way to copy sym links/junctions, or I'm too stupid to figure it out. Tried everything on the Drop As... menu.

With Far Manager, just hit Copy at the bottom of the interface, after making sure that the other window pane is pointed at your destination folder. It's that simple!

I copied my entire User folder! Some links you have to correct afterwards, like application data. If you have Link Shell Extension just right click and change the path in the Link context properties menu. Otherwise they will point to your old drive. Be sure to correct the ones inside application data, AppData\Local, and Temporary Internet Files too. Be sure to TAKE OWNERSHIP before copying!

Also, you need to do this logged in to another Admin profile, or booted into another OS. If you're booted into another OS make sure the links point to the drive letter that the target OS wants, not the drive letter the current OS wants. For example my target OS is J:\users\Me. My Junctions there point to C:\users\Me because C:\ is the drive letter I'll be booted into. (Yes, clicking the links now will open your current OS's folder. Don't worry about it.)

There are Registry entries you have to change. See here.

1
  • Link Shell Extension works, however the instructions are a bit convoluted for copying already existing symlinked-folders: superuser.com/a/1509670/231129 (Link Shell Extension is still worth getting, in my opinion, for the streamlined creation of sym-links, however.)
    – Venryx
    Dec 13, 2019 at 1:33
1

Also I found a shell extension that might make this a bit simpler.

It's demonstrated on HowToGeek here

And the link to the shell extension itself is here

Unfortunately I haven't had a chance to test this myself because I need to do it on a server and I don't particularly want to fiddle around with shell extension on a production server - but I thought it might be useful.

0

This was done using Windows 10 Pro edition. However, I think it is the same on Windows 7 and Windows 8.

First, add the ability to create symlinks to your non-admin user account. This is found in the Local Security Policy (secpol) in "Security Settings>LocalPolicies>User Rights Assignment>Create symbolic links". By adding your non-admin user to this user rights setting, you are allowed to create symbolic links, a permission you need if you copy, and therefore create, a symlink.

Then do this in a command prompt window:

copy /L sourceLocation targetLocation
3
  • I don't see a /l in the copy reference referring to win2008r2 and win2012r2. Mar 9, 2017 at 1:04
  • See if "help copy" in the command prompt lists the /L option. I'm not sure if the server versions of Windows provide the same options as windows 10 and 8, though one could expect it to.
    – eug-
    Mar 18, 2017 at 7:40
  • Not working for me for symlinks of directories.
    – Basj
    Jan 18, 2021 at 14:45
0

Here is a solution in one-line of Python that I copy-paste every time I need it:

import os, glob, shutil; [shutil.copy(f, '.', follow_symlinks=False) for f in glob.glob(r'c:\src_dir_containing_symlinks\*')]   

Now in a more readable form:

SRC = r'c:\test'
DST = '.'

import os, glob, shutil
for f in glob.glob(os.path.join(SRC, '*')):
    shutil.copy(f, DEST, follow_symlinks=False)   
1
  • Does this code really produce symlinks?
    – Cadoiz
    Feb 24, 2021 at 13:54

You must log in to answer this question.

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