copytree if directory exists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Guettler

    #1

    copytree if directory exists

    Hi,

    I need to copy a directory into an existing directory.
    shutil.copytree does complain that the directory already
    exists.

    I need something like "cp -rp": Copy recursively, overwrite
    if file already exist. Preserve mtime and modes if possible.

    A keyword argument "may_exist= 1" for shutil.copytree would be nice.

    Thomas

  • Peter Hansen

    #2
    Re: copytree if directory exists

    Thomas Guettler wrote:[color=blue]
    > I need to copy a directory into an existing directory.
    > shutil.copytree does complain that the directory already
    > exists.
    >
    > I need something like "cp -rp": Copy recursively, overwrite
    > if file already exist. Preserve mtime and modes if possible.
    >
    > A keyword argument "may_exist= 1" for shutil.copytree would be nice.[/color]

    Thomas, shutil.copytree is written in pure Python. Grab the
    source and stick in the appropriate exception handling around
    the call to os.mkdir() and you should have about what you
    need...

    -Peter

    Comment

    • Thomas Heller

      #3
      Re: copytree if directory exists

      Peter Hansen <peter@engcorp. com> writes:
      [color=blue]
      > Thomas Guettler wrote:[color=green]
      >> I need to copy a directory into an existing directory.
      >> shutil.copytree does complain that the directory already
      >> exists.
      >> I need something like "cp -rp": Copy recursively, overwrite
      >> if file already exist. Preserve mtime and modes if possible.
      >> A keyword argument "may_exist= 1" for shutil.copytree would be nice.[/color]
      >
      > Thomas, shutil.copytree is written in pure Python. Grab the
      > source and stick in the appropriate exception handling around
      > the call to os.mkdir() and you should have about what you
      > need...[/color]

      Also, distutils.dir_u til has a fairly flexible copy_tree function.

      Thomas

      Comment

      Working...