import os
import shutil
def coverFiles(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):
open(targetFile, "wb").write(open(sourceFile, "rb").read())
def removeFileInFirstDir(targetDir):
for file in os.listdir(targetDir):
targetFile = os.path.join(targetDir, file)
if os.path.isfile(targetFile):
os.remove(targetFile)
def copyFiles(sourceDir, targetDir):
for file in os.listdir(sourceDir):
if not os.path.exists(targetDir):
os.makedirs(targetDir)
sourceFile = os.path.join(sourceDir, file)
targetFile = os.path.join(targetDir, file)
if os.path.isfile(sourceFile):
open(targetFile, "wb").write(open(sourceFile, "rb").read())
if os.path.isdir(sourceFile):
copyFiles(sourceFile, targetFile)
def copyFiles2(sourceDir, targetDir):
shutil.copytree(sourceDir, targetDir)
if __name__ == '__main__':
copyFiles2(r"C:\Users\Administrator\Desktop\my\szpython1801", r"C:\Users\Administrator\Desktop\my\新建文件夹\麻瓜")