Python folder copying issue -


i'm trying copy directory portable drive main disk using following lines:

temp_command = "xcopy " + new_dir + " " + basedir + "/libraries/installed" #this isn't working. raises error.     if subprocess.check_output(temp_command) == true: # copy file local directory on c: 

and error:

invalid number of parameters traceback (most recent call last):   file "e:/jason core/boot.py", line 103, in <module>     control()   file "e:/jason core/boot.py", line 96, in control     install_libs()   file "e:/jason core/boot.py", line 45, in install_libs     if subprocess.check_output(temp_command) == true: # copy file local directory on c:   file "c:\python27\lib\subprocess.py", line 574, in check_output     raise calledprocesserror(retcode, cmd, output=output) subprocess.calledprocesserror: command 'xcopy c:/downloads/python_libraries e:/libraries/installed' returned non-zero exit status 4 

any suggestions on can change here?

you're using check_output in wrong way.

check_output returns output of command, not true or false, if command succeeded, isn't case here.

now why isn't succeeding?

reasons multiple, obvious 1 that

xcopy c:/downloads/python_libraries e:/libraries/installed 

won't work if input exists & output can written, because you're passing names slashes xcopy, old ms-dos command interprets switches.

the proper command have been:

subprocess.check_output([r"xcopy",r"c:\download\python_libraries",r"e:\libraries\installed"]) 

(note raw prefix avoid backslashes being interpreted python , passing list of parameters if there spaces in paths, quoting handled automatically)

that way of running subprocess.check_output right 1 in general case, in simple case you'd better off with

import shutil shutil.copytree(r"c:\download\python_libraries",r"e:\libraries\installed") 

(no need run command copy files/dirs, python comes batteries included, say: if error there easier understand it)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -