Add feature to copy(), copy2(): dst may be a directory.
Remove unneeded check for '.' / '..' from copytree(). Add some comments.
This commit is contained in:
parent
277206b08e
commit
5980845bd5
|
@ -1,5 +1,6 @@
|
|||
# Module 'shutil' -- utility functions usable in a shell-like program
|
||||
# XXX The copy*() functions here don't copy the data fork on Mac
|
||||
# Module 'shutil' -- utility functions usable in a shell-like program.
|
||||
# XXX The copy*() functions here don't copy the data fork on Mac.
|
||||
# XXX Consider this example code rather than flexible tools.
|
||||
|
||||
import os
|
||||
|
||||
|
@ -40,15 +41,21 @@ def copystat(src, dst):
|
|||
os.chmod(dst, mode)
|
||||
os.utime(dst, st[7:9])
|
||||
|
||||
# Copy data and mode bits ("cp src dst")
|
||||
# Copy data and mode bits ("cp src dst").
|
||||
# Support directory as target.
|
||||
#
|
||||
def copy(src, dst):
|
||||
if os.path.isdir(dst):
|
||||
dst = os.path.join(dst, os.path.basename(src))
|
||||
copyfile(src, dst)
|
||||
copymode(src, dst)
|
||||
|
||||
# Copy data and all stat info ("cp -p src dst")
|
||||
# Copy data and all stat info ("cp -p src dst").
|
||||
# Support directory as target.
|
||||
#
|
||||
def copy2(src, dst):
|
||||
if os.path.isdir(dst):
|
||||
dst = os.path.join(dst, os.path.basename(src))
|
||||
copyfile(src, dst)
|
||||
copystat(src, dst)
|
||||
|
||||
|
@ -58,9 +65,7 @@ def copy2(src, dst):
|
|||
def copytree(src, dst):
|
||||
names = os.listdir(src)
|
||||
os.mkdir(dst, 0777)
|
||||
dot_dotdot = (os.curdir, os.pardir)
|
||||
for name in names:
|
||||
if name not in dot_dotdot:
|
||||
srcname = os.path.join(src, name)
|
||||
dstname = os.path.join(dst, name)
|
||||
#print 'Copying', srcname, 'to', dstname
|
||||
|
|
Loading…
Reference in New Issue