Python shutil.copytree function not working
Question
I feel like I am either missing something basic here are something wonky is going on. I have read the docs and understand that copytree must specify both a source path and a destination path. I am struggling with the destination part. My code is below...
from shutil import copytree
copytree("C:\Users\D34DLYHAX\Pictures", "C:\Users\D34DLYHAX\Pictures\Temp\\")
The tree is copied without any troubles; however, the folder "Temp" is not being created and the copied tree is not being placed inside of it. Instead, the copied tree is placed at "C:\Users\D34DLYHAX\Pictures\My Pictures." Why is this happening? Unless I have read the documents incorrectly, shouldn't the copied tree be inserted in Temp with Temp as the source folder?
Thanks for your help and answers.
--Okay, now it is getting stranger still. When I go to view the copied folder it is named "My Pictures," no problems there. However, if I throw the copied tree into the recycling bin and view the contents of the recycling bin the copied tree is now named "Temp". What is going on?
Solution 2
Not quite sure what the issue was, but this seems to be working just fine...
from datetime import date
from shutil import copytree
currentDate = str(date.today())
currentDate = currentDate.replace("-", ".")
DESTINATION = "C:\\Users\\D34DLYHAX\\Desktop\\Backup " + currentDate
copytree("C:\\Users\\D34DLYHAX\\Pictures\\", DESTINATION + "\\My Pictures")
OTHER TIPS
Quick solution is to use forward slashes. I suspect you are not escaping things correctly.
from shutil import copytree
copytree("C:/Users/D34DLYHAX/Pictures", "C:/Users/D34DLYHAX/Pictures/Temp")
Or leave off the trailing //
from shutil import copytree
copytree("C:\Users\D34DLYHAX\Pictures", "C:\Users\D34DLYHAX\Pictures\Temp")
Another thing that might cause you a disaster is copying a folder inside itself. Don't do that, think about how it could go wrong. Copy it outside itself.
Remember if you want symplinks copied pass symlinks=True