Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcopy with Python

Tags:

python

xcopy

I'm trying to get xcopy working with python to copy files to a remote system. I am using a very simple test example:

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 the xcopy directly from the command line works fine. Any ideas?

Thanks

like image 579
DJMcCarthy12 Avatar asked Oct 27 '25 09:10

DJMcCarthy12


1 Answers

\t is a tab character. I'd suggest using raw strings for windows paths:

src = r"C:\<Username>\Desktop\test2.txt"
dst = r"C:\Users\<Username>"

This will stop python from surprising you by interpreting some of your backslashes as escape sequences.

like image 193
FatalError Avatar answered Oct 29 '25 22:10

FatalError



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!