0

I have this command to run:

'xcopy /e "%s" "%s"'%(executablesPath + "\\*", sourcePath+"\\Executables\\")

which is formatted to:

xcopy /e "I:\Storage$\tools\Executables\*" "C:\Win10x64-1903\Executables\"

and ran within:

subprocess.run(shlex.split(command))

What is causing the error ValueError: No closing quotation?

Aurora
  • 3
  • 1
  • 1
    `"C:\Win10x64-1903\Executables\"` should be `"C:\Win10x64-1903\Executables"` (without the backslash in the end). Better yet: don't use an external command to copy files, use `shutil` module – Jean-François Fabre Sep 17 '19 at 18:50

1 Answers1

0

shlex.split doesn't like the last backslash before the double quote. It seems like you want to escape this quote, hence the message.

quick fix: replace sourcePath+"\\Executables\\" by os.path.join(sourcePath,"Executables")

better fix: don't compose a command line just to split it again. Just use a list of arguments

subprocess.run(["xcopy","/e",os.path.join(executablesPath,"*"),os.path.join(sourcePath,"Executables")])

Better yet, use shutil.copytree to recursively copy a directory. No need for a non-portable external command. Something (untested) like:

import shutil
shutil.copytree(executablesPath,os.path.join(sourcePath,"Executables"))
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • While this is marked as the acceptable answer, it should be made aware that shutil.copy doesn't always make good for copying subdirectories and their contents. I have only been able to make good use of shutil.copy for individual files and using it within a recursive function for nested directories. – Aurora Sep 17 '19 at 20:23
  • you're right. I've been slightly evasive about `shutil.copytree`. It has many limitations. Sometimes you have to create the dirs, sometimes not, ... there's some tuning to do but at least it's portable and doesn't depend on old xcopy – Jean-François Fabre Sep 17 '19 at 20:25