Batch script to copy symbolic links as is but not overwrite source if already exist
-
18-06-2021 - |
سؤال
I've tried Fastcopy and Robocopy and both seem to be able to do either one of those operation but not both.
For files like (BEFORE COPYING)
D:\SYMLINKSOURCE\file1 <<symlink from D:\Source\file1 **edit
D:\SYMLINKSOURCE\file2 <<symlink from D:\Source\file1 **edit
D:\DESTINATIONxx\file2 <<not a symlink
I want to copy D:\SYMLINKSOURCE\*
to D:\DESTINATIONxx
but without overwriting D:\DESTINATIONxx\file1
such that after copying it looks like
(AFTER COPYING)
D:\SYMLINKSOURCE\file1 <<symlink from D:\Source\file1
D:\SYMLINKSOURCE\file2 <<symlink from D:\Source\file2
D:\DESTINATIONxx\file1 <<symlink from D:\Source\file1
D:\DESTINATIONxx\file2 <<not a symlink
I tried this to not overwrite but it doesn't preserve Symbolic links and instead copies resolved files Copy files without overwrite
robocopy "D:\SYMLINKSOURCE" "D:\DESTINATION" /E /XC /XN /XO
(AFTER COPYING)
D:\SYMLINKSOURCE\file1 <<symlink from D:\Source\file1
D:\SYMLINKSOURCE\file2 <<symlink from D:\Source\file2
D:\DESTINATIONxx\file1 <<not a symlink < i wanted this as symlink
D:\DESTINATIONxx\file2 <<not a symlink
and adding /SL to preserve symlinks overwrites everything.
robocopy "D:\SYMLINKSOURCE" "D:\DESTINATION" /E /XC /XN /XO /SL
(AFTER COPYING)
D:\SYMLINKSOURCE\file1 <<symlink from D:\Source\file1
D:\SYMLINKSOURCE\file2 <<symlink from D:\Source\file2
D:\DESTINATIONxx\file1 <<symlink from D:\Source\file1
D:\DESTINATIONxx\file2 <<symlink from D:\Source\file1 < i did not want this overwritten
Is there any way I can achieve what I want?
المحلول
The only way I can see on how to do this would be to use two seperate robocopy's first for the non-link files and later for the link-files you want to copy as links. Assuming that there are more normal files than links, you could run your:
robocopy "D:\SYMLINKSOURCE" "D:\DESTINATION" /E /XC /XN /XO
Then copying the actual links by naming the individually (or using some naming convention, like sl-file1
and usa a sl*
pattern) and thus fixing the erroneously overwritten links with:
robocopy "D:\SYMLINKSOURCE\file1" "D:\DESTINATION" /E /XC /XN /XO /SL