[Tutor] Copy without overwrite?

Bernard Lebel python at bernardlebel.com
Tue Sep 21 14:31:25 CEST 2004


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
>
>




More information about the Tutor mailing list