该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
def copy_dir(sourceDir,destDir):
for file in os.listdir(sourceDir):
sourceFile = os.path.join(file)
destFile = os.path.join(file)
#此处打印的结果全是False 不管是文件还是文件夹
print sourceFile,os.path.isfile(sourceFile)\
,os.path.isdir(sourceFile),os.path.realpath(sourceFile)
if(os.path.isfile(sourceFile)):
print sourceFile
os.mkdirs(destDir)
if not os.path.exist(destDir):
os.mkdirs(destDir)
if not os.path.exist(destDir) \
or (os.path.exist(destFile) \
and (os.path.getsize(sourceFile) \
!= os.path.getsize(destFile) )):
open(destFile,"w+").write(open(sourceFile,"rb").read())
elif os.path.isdir(sourceFile):
copy_dir(sourceFile,destFile)
print "Copy End."
#main函数
if __name__ == "__main__":
copy_dir("E:\\Pythonwork\\test_1\\","./dest_1/")