def copyfile(src, dst):
try:
f1 = open(src, "rb")
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))
f2 = open(dst, "w+b")
while True:
buf = f1.read(16*1024)
if not buf:
break
f2.write(buf)
st = os.stat(src)
mode = S_IMODE(st.st_mode)
os.chmod(dst, mode)
os.utime(dst, (st.st_atime, st.st_mtime))
except:
print "copy", src, "to", dst, "failed!"
return -1
return 0
评论列表
文章目录