pythoncopyshutilcopytree

Python shutil.copytree function not working


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

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