Windows xcopy is not working in python
Asked Answered
H

1

2

When I am doing

xcopy "D:\Accessories\My File\read-me.rtf" "D:\Any Folder\Destn"

It is copying fine

Same thing I am doing in python (2.7)

import os
source = "D:\Accessories\My File\read-me.rtf"
target = "D:\Any Folder\Destn"
output = os.system ("xcopy %s %s" % (source, target))

But this code is throwing error that Invalid number of parameters

Is it a right way to invoke ? Any suggestion ?

Hedges answered 20/2, 2013 at 8:40 Comment(0)
D
4

There are spaces in your "source" and "target" pathnames. Try quoting it in the os.system call ie

output = os.system ("""xcopy "%s" "%s" """ % (source, target))
Discourteous answered 20/2, 2013 at 8:45 Comment(2)
Let me chk, I was trying with \"%s\"Hedges
In another case I am getting Parse Error. Any idea ?Hedges

© 2022 - 2024 — McMap. All rights reserved.