2

I am trying to exclude a folder from xcopy to avoid a cyclic copy error, my script is doing this..

xcopy c:\test c:\test\myfolder\tmp /EXCLUDE:c:\test\myfolder\exclude.txt /E

My exclude.txt file has this inside..

c:\test\myfolder
\myfolder\

But it still giving me the cyclic copy error, where am I going wrong?

fightstarr20
  • 11,682
  • 40
  • 154
  • 278
  • Try copying to somewhere outside of where you are copying from. – Mark Setchell Jul 04 '18 at 16:50
  • Thats precisely the opposite of what i am trying to achieve :) I need to copy to the same place – fightstarr20 Jul 04 '18 at 17:03
  • I was suggesting that to see if the error message goes away. I suspect `xcopy` is not the smartest program and it is tripping up on itself. It was a test - not a permanent solution. – Mark Setchell Jul 04 '18 at 17:16
  • 3
    __XCOPY__ makes the check for destination directory being a subdirectory of source directory without taking the entries in exclude list file into account. You could perhaps workaround this issue with `subst Z: c:\test\myfolder\tmp` and `xcopy.exe c:\test Z:\ /EXCLUDE:c:\test\myfolder\exclude.txt /E` and `subst Z: /D` (not verified by me). – Mofi Jul 04 '18 at 17:22
  • 1
    What about using [`robocopy`](http://ss64.com/nt/robocopy.html)? like: `robocopy "C:\test" "C:\test\myfolder\tmp" /XD "C:\test\myfolder" /E` – aschipfl Jul 04 '18 at 17:38
  • Robocopy was a perfect fit, thanks for the advice! – fightstarr20 Jul 04 '18 at 17:56
  • @Mofi, your smart `subst` approach works fine, I just verified it! – aschipfl Jul 04 '18 at 17:58

2 Answers2

3

As Mofi already pointed out in his comment, the /EXCLUDE option of xcopy is regarded too late. Additionally, this feature is very poor -- refer to this answer or this answer of mine (shameless self-promotion...).

Let me recommend to use robocopy instead, which supports nice exclusion options:

robocopy "C:\test" "C:\test\myfolder\tmp" /XD "C:\test\myfolder" /E
aschipfl
  • 33,626
  • 12
  • 54
  • 99
1

Going on from aschipfl advice in the comments, I solved this by using RoboCopy with the following...

robocopy C:\test C:\test\myfolder\tmp /XD myfolder
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
fightstarr20
  • 11,682
  • 40
  • 154
  • 278