31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
#! python 3
|
|
# -*- coding:utf-8 -*-
|
|
# Autor: Li Rong Yang
|
|
# '''
|
|
# Copy指定格式的文件到新文件夹
|
|
# '''
|
|
import shutil,os
|
|
#定义函数,接收传入的值
|
|
def CHeckFileUUID(sourcefile,fileclass,destinationfile):
|
|
#遍历目录和子目录
|
|
for filenames in os.listdir(sourcefile):
|
|
#取得文件或文件名的绝对路径
|
|
filepath = os.path.join(sourcefile,filenames)
|
|
#判断是否为文件夹
|
|
if os.path.isdir(filepath):
|
|
#如果是文件夹,重新调用该函数
|
|
CHeckFileUUID(filepath,fileclass,destinationfile)
|
|
#判断是否为文件
|
|
elif os.path.isfile(filepath):
|
|
#如果该文件的后缀为用户指定的格式,则把该文件复制到用户指定的目录
|
|
if filepath.endswith(fileclass):
|
|
#dirname = os.path.split(filepath)[-1]
|
|
#给出提示信息
|
|
print('Copy %s'% filepath +' To ' + destinationfile)
|
|
#复制该文件到指定目录
|
|
shutil.copy(filepath,destinationfile)
|
|
#函数调用
|
|
source = 'd:\\project\\DB\\DragonBall_3\\assets\\resources\\data\\en'
|
|
typemeta = '.meta'
|
|
CHeckFileUUID(source,typemeta,'d:\\project\\DB\\DragonBall_3\\copy_png')
|