I found the cause and have a fix for it. Attached is the patch (on top of Emacs 24.5.1).:
The cause is the order of the function "shell-quote-argument" and "file-name-nondirectory" is wrong. So if I have a target directory name "c:\wlynn\tmp\xyz", the buggy code will first quote it into
"\"c:\wlynn\tmp\xyz\"", and the file-name-nondirectory function will strip the last part, ending with something like this:
"\"c:\wlynn\tmp"
See the dangling leading quote?
I verified that it works now. Let me know if you think the patch is good and is merged into the latest dev branch. Thanks.