Windows xcopy is not working in python

僤鯓⒐⒋嵵緔 提交于 2019-12-24 00:57:12

问题


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 ?


回答1:


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))


来源:https://stackoverflow.com/questions/14975481/windows-xcopy-is-not-working-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!