Xcopy with Python
I am trying to get xcopy to work with python to copy files to a remote system. I am using a very simple test case:
import os
src = "C:\<Username>\Desktop\test2.txt"
dst = "C:\Users\<Username>"
print os.system("xcopy %s %s" % (src, dst))
But for some reason, when I run this, I get:
Invalid number of parameters
4
Running xcopy directly from the command line works great. Any ideas?
thank
+3
source to share
3 answers
In addition to using the original string literals, use subprocess
instead os.system
- it will take care of quoting your arguments correctly if they contain spaces. Thus:
import subprocess
src = r'C:\<Username>\Desktop\test2.txt'
dst = r'C:\Users\<Username>'
subprocess.call(['xcopy', src, dst])
+3
source to share