Quote your variables in bash, not doing them will split your words in the variable to individual tokens and the command that uses that variable will be getting multiple words when it was expected a single string (See Word Splitting in shell)
year=$(stat -c %y "$pathfile" | cut -d '-' -f1)
I suppose your problem is in your variable you are using " along with the \ escape sequence. You need to do either of the one.
pathfile="/path/to/file with spaces"