Python Library Reference
Previous: Up: 11.10 shutil Next:


11.10.1 Example

This example is the implementation of the copytree() function, described above, with the docstring omitted. It demonstrates many of the other functions provided by this module.

def copytree(src, dst, symlinks=0):
 names = os.listdir(src)
 os.mkdir(dst)
 for name in names:
 srcname = os.path.join(src, name)
 dstname = os.path.join(dst, name)
 try:
 if symlinks and os.path.islink(srcname):
 linkto = os.readlink(srcname)
 os.symlink(linkto, dstname)
 elif os.path.isdir(srcname):
 copytree(srcname, dstname, symlinks)
 else:
 copy2(srcname, dstname)
 except (IOError, os.error), why:
 print "Can't copy %s to %s: %s" % (`srcname`, `dstname`, str(why))

Python Library Reference
Previous: Up: 11.10 shutil Next:

Release 2.5.2, documentation updated on 21st February, 2008.
See About this document... for information on suggesting changes.

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