I'm trying to write a script to copy files recursively from a particular folder except files
C are directories and
extn is just some generic extension. This is what I have:
#!/usr/local/bin/zsh setopt EXTENDED_GLOB TMPDIR=/tmp/test cp -pR $(dirname $0)/**~(*.foo/*|*/bar.txt|*.abc|qux.txt) $TMPDIR
However this doesn't do the negation of the pattern as expected. I think I do know why — although the pattern is correct (as seen with
cp -R is not aware of the pattern, and enters a directory that it is "not supposed to", and once in there, the pattern is no longer valid.
How do I modify the above to do what I want? I guess it is possible with
xargs, but I'm drawn towards the clarity of the above and would prefer something similar (but if it's the wrong way to do it, I'd be perfectly happy with a different solution).