44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
#! python 3
|
|
# -*- coding:utf-8 -*-
|
|
# Autor: Li Rong Yang
|
|
# '''
|
|
# Copy指定格式的文件到新文件夹
|
|
# '''
|
|
import shutil,os
|
|
def INcontaintUUId(filenames,finalfile):
|
|
dic = os.listdir(finalfile)
|
|
for copyfiles in dic:
|
|
if copyfiles[0:35] in filenames[0:35]:
|
|
return True
|
|
return False
|
|
|
|
#定义函数,接收传入的值
|
|
def CFindImgs(sourcefile,fileclass,destinationfile,finalfile):
|
|
#遍历目录和子目录
|
|
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)
|
|
CFindImgs(filepath,fileclass,destinationpath,finalfile)
|
|
#判断是否为文件
|
|
elif os.path.isfile(filepath):
|
|
iscopy = INcontaintUUId(filenames,finalfile)
|
|
#如果该文件的后缀为用户指定的格式,则把该文件复制到用户指定的目录
|
|
if iscopy:
|
|
# if filepath.endswith(fileclass):
|
|
#给出提示信息
|
|
print('Copy %s'% filepath +' To ' + destinationfile)
|
|
#复制该文件到指定目录
|
|
shutil.copy(filepath,destinationfile)
|
|
#函数调用
|
|
source = 'd:\\FC\\project\\project\\build\\resources'
|
|
destination = 'd:\\FC\\project\\project\\build\\first.1.0.30\\assets\\resources'
|
|
final = 'd:\\FC\\project\\project\\copy_png'
|
|
CFindImgs(source,'',destination,final)
|