Copy directory tree without copying files

Peter Otten __peter__ at web.de
Wed Sep 23 11:24:37 EDT 2009


Jeremy Conlin wrote:
> I am trying to copy a folder hierarchy from one location to another.
> I can use the shutil.copytree function to copy the folder tree, but I
> don't want the files copied, just the folders. What is a good way to
> approach this?

The easiest is
def ignore(folder, names):
 return set(n for n in names if not
 os.path.isdir(os.path.join(folder, n)))
shutil.copytree(source, dest, ignore=ignore)
Peter


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /