So you are not copying all the contents of the directory, just some specific file that might be one of many? Also, the destination path may not yet exist so you need to create the appropriate directory structure in the destination?
I was unfamiliar with the --parents flag for the cp command but I think I see what you are doing. If I understand correctly, it works if there is path information but does not if there is no path information?
I don't think the script needs to be very hard. Something like
1) parse out the path part that comes after path/origin
2) concatenate the parsed-out path to the destination path. if this directory doesn't exist, use mkdir with $recursive param of TRUE
3) copy the file.