We mainly use the OS. path and shutil modules to copy and delete files. You can modify the relevant code as needed.
#! /Usr/bin/env python #-*-coding: UTF-8-*-import OS. path import shutil import time, datetime def copyFiles (sourceDir, targetDir): # copy all files in a directory to the specified directory if sourceDir. find (". svn ")> 0: return 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 (tar GetDir) 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) def removeFileInFirstDir (targetDir): # delete all files in the first-level directory for file in OS. listdir (targetDir): targetFile = OS. path. join (targetDir, file) if OS. path. isfile (targetFile): OS. remove (targetFile) def coverFiles (sourceDir, targetDir): # copy all files in the first-level directory to the specified directory for file in OS. listdir (sourceDir): sourceFile = OS. path. join (sourceDir, file) targetFile = OS. path. join (targetDir, file) # cover the files if OS. path. isfile (sourceFile): open (targetFile, "wb "). write (open (sourceFile, "rb "). read () def moveFileto (sourceDir, targetDir): # copy the specified file to the shutil directory. copy (sourceDir, targetDir) def writeVersionInfo (targetDir): # write the text file open (targetDir, "wb") to the specified directory "). write ("Revison:") def getCurTime (): # returns the current date to use nowTime = time when creating the specified directory. localtime () year = str (nowTime. tm_year) month = str (nowTime. tm_mon) if len (month) <2: month = '0' + month day = str (nowTime. tm_yday) if len (day) <2: day = '0' + day return (year + '-' + month + '-' + day) if _ name _ = "_ main _": # main Function print "Start (S) or Quilt (Q) \ n" flag = True while (flag): answer = raw_input () if answer = 'q': flag = False elif answer = 's': formatTime = getCurTime () targetFoldername = "Build" + formatTime + "-01" Target_File_Path + = targetFoldername copyFiles) moveFileto (AssistantGui_File_Path, Target_File_Path) writeVersionInfo (Target_File_Path + "\ test.txt") print "all sucess" else: print "not the correct command"