When using Windows 10/11 and trying to copy a directory tree with symlinks, tools like xcopy and robocopy indeed do not handle symlinks the same way Linux does, where you'd expect them to follow the symlink and copy the target file by default. It seems that Windows tools, even though they provide options, don't always behave as expected with .lnk
files (which are more like Windows shortcuts, not traditional symlinks).
Here are some options you can try:
- Using Robocopy with
/SL
Option
Though you mentioned trying robocopy, ensure you are using the /SL
switch, which specifies that robocopy should copy the symbolic link itself and not the target.
Here's a typical robocopy command:
robocopy C:\source\path C:\destination\path /E /COPYALL
This command should, in theory, copy all file attributes and the target of symlinks (when not using /SL
). However, .lnk
files created by Windows Explorer might still behave differently.
- Use a Third-Party Tool
If the above methods do not work as expected, consider using third-party tools that handle symbolic links more reliably. Tools like Cygwin or rsync (for Windows) can better handle file operations similar to how Linux does.
For example, you can install Cygwin or Git Bash (which includes rsync
), and use:
rsync -av --copy-links /cygdrive/c/source/path /cygdrive/c/destination/path
This --copy-links
option will ensure that symlink targets are copied rather than the symlinks themselves.
- Convert
.lnk
Files to NTFS Symlinks
Windows .lnk
files are technically shortcuts, not true symbolic links in the Unix/Linux sense. If you have access to mklink, you can try converting .lnk
files to actual NTFS symlinks using:
mklink /D linkName targetDirectory
Once converted to NTFS symlinks, the native tools like robocopy should handle them as you intend.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin