[Tutor] Copy without overwrite?
Kent Johnson
kent_johnson at skillsoft.com
Tue Sep 21 14:59:12 CEST 2004
You are right about copytree(). But you can open shutil.py, copy the method
to your own code, and modify it easily to do what you want. (Just add a
test of os.path.exists().) The doc comment even hints that that is the
expected usage :-)
Looking at copytree() I'm actually not sure what keeps it from working if
the directory already exists; the docs for os.mkdir() don't say it will
fail if the dir exists.
Kent
At 02:31 PM 9/21/2004 +0200, Bernard Lebel wrote:
>Hi Kent,
>
>Unless I'm missing something... os.copytree() expects the destination
>directory to not exists. It it
>exists, the function aborts instead of visiting the said directory and go
>further down the tree.
>Plus, I don't think it handles individual files (files are copied, but no
>determining of existence
>is performed).
>
>Let me know if I'm missing something.
>
>
>Thanks
>Bernard
>
>----- Original Message -----
>From: "Kent Johnson" <kent_johnson at skillsoft.com>
>To: <tutor at python.org>
>Sent: Tuesday, September 21, 2004 2:17 PM
>Subject: Re: [Tutor] Copy without overwrite?
>
>
> > shutil.copytree() is almost what you want. You could copy it (from
> > Python/Lib/shutil.py) and check os.path.exists() before the actual copying
> > is done.
> >
> > At 11:59 AM 9/21/2004 +0200, Bernard Lebel wrote:
> > >Hello,
> > >
> > >Is there a simple way to copy files and directory without any overwriting
> > >if the destination tree
> > >structure contains files and directory of the same name? Basically that
> > >would just add new elements
> > >to the destination structure, and leave the existing structure intact.
> > >
> > >
> > >Thanks
> > >Bernard
> > >
> > >
> > >_______________________________________________
> > >Tutor maillist - Tutor at python.org
> > >http://mail.python.org/mailman/listinfo/tutor
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list