Python Forum
Shutil attempts to copy directories that don't exist
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shutil attempts to copy directories that don't exist
#1
I'm attempting to copy the Documents folder under the Windows userprofile, the shutil.copytree(documents, destination) works partially. It will copy the Documents to the root of the destination, in this case the R: drive, and it will also attempt to copy the other Windows special folders (My Music, My Pictures, etc..), even if they don't exist under Documents.

import shutil


def main():

   try:

       user_profile = os.getenv("USERPROFILE")

       # Construct a full path to the documents folder 
       documents = Path(user_profile).joinpath("Documents")

       # Destination for the Documents folder
       destination = Path("R:\\Test")

       shutil.copytree(documents, destination)            

   except (FileNotFoundError, shutil.Error) as error:
       print(error)


if __name__ == '__main__':
    main()
This is a excerpt of the exception that is thrown:
[('C:\\Users\\ConsoleGeek\\Documents\\My Music', 'R:\\Test\\My Music', 
"[WinError 5] Access is denied: 'C:\\\\Users\\\\ConsoleGeek\\\\Documents\\\\My Music'")
...
None of these folders exist under Documents, so I don't fully understand why shutil attempts to copy these special folders. If I attempt to copy a regular folder under the user profile, it works.

I also posted this question on Stack Overflow, but no one has answered.
Reply


Messages In This Thread
Shutil attempts to copy directories that don't exist - by ConsoleGeek - Oct-28-2019, 10:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 407 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Organization of project directories wotoko 3 617 Mar-02-2024, 03:34 PM
Last Post: Larz60+
  use of shutil.copytree with ENOTDIR exception yan 2 1,092 Nov-29-2023, 03:02 PM
Last Post: yan
  Failed attempts to load Microsoft Appstore Python DLLs piyushd 0 532 Oct-31-2023, 10:43 AM
Last Post: piyushd
  UndefinedEnvironmentName: 'extra' does not exist in evaluation environment EarthAndMoon 3 1,889 Oct-09-2023, 05:38 PM
Last Post: snippsat
  Listing directories (as a text file) kiwi99 1 930 Feb-17-2023, 12:58 PM
Last Post: Larz60+
  shutil.move make data corrupt kucingkembar 0 889 Feb-01-2023, 01:30 PM
Last Post: kucingkembar
  rename same file names in different directories elnk 0 785 Nov-04-2022, 05:23 PM
Last Post: elnk
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 5 1,783 Aug-28-2022, 07:11 AM
Last Post: Melcu54
  check if a file exist on the internet and get the size kucingkembar 6 1,920 Apr-16-2022, 05:09 PM
Last Post: kucingkembar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020