#! python 3 # -*- coding:utf-8 -*- # Autor: Li Rong Yang # ''' # Copy指定格式的文件到新文件夹 len = 36 md5cache = 5 # ''' from re import sub import shutil,os def INcontaint(fliename,sourcefile,destinationfile): for newfilename in os.listdir(destinationfile): newfilepath = os.path.join(destinationfile,newfilename) sourcepath = os.path.join(sourcefile,newfilename) if os.path.isdir(newfilepath): INcontaint(fliename,sourcefile,newfilepath) elif os.path.isfile(newfilepath): fileval = fliename newfileval = newfilename if newfileval[0:35] in fileval[0:35]: #移除源文件 os.remove(sourcepath) print(fliename+' XXXXXXXXXXXX '+sourcepath) return True return False #定义函数,接收传入的值 def SFileToDFile(sourcefile,fileclass,destinationfile): #遍历目录和子目录 for filenames in os.listdir(sourcefile): #取得文件或文件名的绝对路径 filepath = os.path.join(sourcefile,filenames) destinationpath = os.path.join(destinationfile,filenames) #判断是否为文件夹 if os.path.isdir(filepath): isExists=os.path.exists(destinationpath) if not isExists: os.makedirs(destinationpath) #如果是文件夹,重新调用该函数 SFileToDFile(filepath,fileclass,destinationpath) #判断是否为文件 elif os.path.isfile(filepath): #如果该文件的后缀为用户指定的格式,则把该文件复制到用户指定的目录 iscontaint = INcontaint(filenames,sourcefile,destinationfile) #if iscontaint: #给出提示信息 #print('Copy %s'% filepath +' To ' + destinationfile) #复制该文件到指定目录 #shutil.copy(filepath,destinationfile) # print('==========') #函数调用 SFileToDFile('d:\\FC\\project\\project\\build\\resources','','d:\\FC\\project\\project\\build\\first.1.0.30\\assets\\resources')