文件拷贝

#coding=utf-8
import os 
import os.path 
import shutil 
import time,  datetime

def copyFiles(sourceDir,  targetDir): 
    for file in os.listdir(sourceDir): 
        sourceFile = os.path.join(sourceDir,  file) 
        targetFile = os.path.join(targetDir,  file) 
        if os.path.isfile(sourceFile): 
            if not os.path.exists(targetDir):  
                os.makedirs(targetDir)  
            if not os.path.exists(targetFile) or (os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))):  
                open(targetFile, "wb").write(open(sourceFile, "rb").read()) 
        if os.path.isdir(sourceFile): 
            First_Directory = False 
            copyFiles(sourceFile, targetFile)
print copyFiles("/home/user/Application/tomcat/apache-tomcat-8.0.30/wtpwebapps/CLZ/static/upload/", "./")

 服务器文件备份

原文地址:https://www.cnblogs.com/guoke-jsp/p/7503485.html