Skip to content

shutil.copytree makedirs exception #67826

Closed

Description

@yuriylevchenko
BPO 23638
Nosy @vadmium
Superseder
  • bpo-20849: add exist_ok to shutil.copytree
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2015-03-12.13:07:10.877>
    created_at = <Date 2015-03-11.10:41:47.229>
    labels = ['type-bug', 'library']
    title = 'shutil.copytree makedirs exception'
    updated_at = <Date 2015-03-12.13:07:10.849>
    user = 'https://bugs.python.org/yuriylevchenko'

    bugs.python.org fields:

    activity = <Date 2015-03-12.13:07:10.849>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-03-12.13:07:10.877>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2015-03-11.10:41:47.229>
    creator = 'yuriy_levchenko'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 23638
    keywords = []
    message_count = 3.0
    messages = ['237858', '237907', '237925']
    nosy_count = 2.0
    nosy_names = ['yuriy_levchenko', 'martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '20849'
    type = 'behavior'
    url = 'https://bugs.python.org/issue23638'
    versions = ['Python 3.4']

    Activity

    1. yuriylevchenko commented on Mar 11, 2015

      yuriylevchenkomannequin
      MannequinAuthor

      We have a code:
      names = os.listdir(src)
      if ignore is not None:
      ignored_names = ignore(src, names)
      else:
      ignored_names = set()

          os.makedirs(dst)
              
          errors = []

      But if I had created this folder. I have exception.

      Maybe add "if"?

          if os.path.isdir(dst) is False:
              os.makedirs(dst)
              pass
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Mar 11, 2015
    3. vadmium commented on Mar 11, 2015

      @vadmium
      Member

      In case it’s not clear to others, the first bit of code is from the shutil.copytree() implementation at Lib/shutil.py:303.

      The documentation currently says “The destination directory . . . must not already exist”. Yuriy seems to be proposing to make copytree() use the existing destination directory, and only create it if it does not already exist. Perhaps you might be interested in bpo-20849, which proposes passing the os.makedirs(exist_ok=...) flag through, which would allow this functionality in a backwards-compatible way.

    4. yuriylevchenko commented on Mar 12, 2015

      yuriylevchenkomannequin
      MannequinAuthor

      Thanks for the clarifications. Yes parameter will be a good solution!

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions