I found this solution to searching while excluding one directory in the answer to another question:
grep -r --exclude-dir="/x/y/z" 'pattern' /x/y
It seems --exclude-dir
matches just the directory name, not its path. So, you can try
grep -r --exclude-dir=z 'pattern' /x/y
It might skip /x/y/a/b/c/z
also, though.