I need a function that lets me copy a folder and what is in the folder into another existing folder. I have tried "shutil.copy", "shutil.copy2" and shutil.copytree" none of these do what I want. I am on python 3.6.2 on windows 10. I am still learning this language so don't make the explanations to complicated.
Asked
Active
Viewed 445 times
-2
-
1It might help if you explained what the functions you mentioned lack that you're looking for. – glibdud Jan 26 '18 at 16:43
-
sure, copy 1 and two only copy a specific file. i want to copy the hole folder. copy tree copys the hole directory and I just want one folder and in copy tree one of the directories can not already exist. – Jacob Knuth Jan 26 '18 at 18:33
1 Answers
0
Here's something:
import os
def copyfolder(folder,newfolder):
os.system("xcopy \""+folder+"\" \""+newfolder+"\" /h /i /c /k /e /r /y")

Qwerty
- 1,252
- 1
- 11
- 23
-
would this work if i am just trying to copy a folder and what it contains in to an existing folder. – Jacob Knuth Jan 26 '18 at 18:59
-
-
-
def copyfolder(folder,newfolder): os.system("xcopy "+folder+" "+newfolder+" /e /i /h") copyfolder("C:/Users/jacob/Desktop/New folder", "C:/Users/jacob/Pictures/Camera Roll") – Jacob Knuth Jan 26 '18 at 19:13
-
-
-
-
-
def copyfolder(folder,newfolder): os.system("xcopy "+folder+" "+newfolder+" /h /i /c /k /e /r /y") copyfolder("C:/Users/jacob/Desktop/New folder", "C:/Users/jacob/Pictures/Camera Roll") – Jacob Knuth Jan 26 '18 at 19:17
-
-
-
-
@JacobKnuth No problem. The problem was the fact that you have a space in your directory, so It needs quotes or it will think it is a seperate directory after the space. – Qwerty Jan 26 '18 at 19:31