54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
#! python 3
|
|
# -*- coding:utf-8 -*-
|
|
# Autor: Li Rong Yang
|
|
# '''
|
|
# Copy指定格式的文件到新文件夹 len = 36 md5cache = 5
|
|
# '''
|
|
from re import sub
|
|
import shutil,os
|
|
|
|
def INcontaint(fliename,destinationfile):
|
|
for newfilename in os.listdir(destinationfile):
|
|
newfilepath = os.path.join(destinationfile,newfilename)
|
|
if os.path.isdir(newfilepath):
|
|
INcontaint(fliename,newfilepath)
|
|
elif os.path.isfile(newfilepath):
|
|
fileval = fliename
|
|
newfileval = newfilename
|
|
if newfileval[0:35] in fileval[0:35]:
|
|
if newfileval[37:41] != fileval[37:41]:
|
|
#移除源文件
|
|
os.remove(newfilepath)
|
|
# print(fliename+' XXXXXXXXXXXX '+newfilepath)
|
|
return True
|
|
else:
|
|
return False
|
|
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,destinationfile)
|
|
if iscontaint:
|
|
#给出提示信息
|
|
print('Copy %s'% filepath +' To ' + destinationfile)
|
|
#复制该文件到指定目录
|
|
shutil.copy(filepath,destinationfile)
|
|
# print('==========')
|
|
#函数调用
|
|
SFileToDFile('d:\\project\\DB\\DragonBall_5\\build\\DragonBall5\\res','.json','d:\\project\\DB\\DragonBall_5\\tools\\basezip\\res')
|