实现匹配文件(并自定义命名)的批量拷贝,后续上传改良版

#! usr/bin/env python
# -*- coding: utf-8 -*-
#实现对文件的自定义命名的并批量复制,脚本并未对异常情况进行处理

import os
import datetime
import time
import fnmatch
import re
import shutil

time = time.strftime("%Y%m%d%H%M%S")   #定义时间的输出格式

files = ["dday-collect", "dday-launcher", "dday-mediaserver",
         "dday-music", "dday-navigation", "dday-navigation-amap-concept",
         "dday-ota", "dday-podcast", "dday-system", "dday-voice",
         "tsd-bluetooth", "tsd-cardvr", "tsd-news", "tsd-settings"]
toPath='/home/uftp/upload/999.版本发布'
toPath_debug = toPath + "/debug/"
#print toPath_debug
toPath_release = toPath + "/release/"
os.chdir(toPath_debug)
path1 = "Version_debug_" + time
os.mkdir(path1)
os.chdir(toPath_release)
path2 = "Version_release_" + time
os.mkdir(path2)
# print path
# files=["dday-bluetooth","dday-cardvr"]
os.system("cd ..")
# filedir = 'E:\\Program Files\\Jenkins\\workspace\\dday-bluetooth\\build\\outputs\\apk'
for file in files:      #根据files遍历文件夹下的子文件夹
    filedir="/home/tuyou/jenkins/workspace/"+file+"/build/outputs/apk/"
    #filedir = "E:\\LOG\\12"
    for parent, dirnames, filenames in os.walk(filedir):        #os.walk的使用

        for filename in filenames:              
            # 匹配release版本APK文件
            # print filename
            if fnmatch.fnmatch(filename, "*release.apk"):       #fnmatch 的使用
                filereleaseapk = filedir + "/" + filename
                # print filereleaseapk
                aapt = os.popen("aapt d badging " + filereleaseapk)     #获取apk 的信息
                s = aapt.read()
                pattern = re.compile("versionName='(.*)\.(.*)\.(.*).*'", re.I)   #正则匹配包信息中的versionName版本号
                re1 = re.findall(pattern, s)
                version = str(re1[0][0] + "." + re1[0][1] + "." + re1[0][2])
                # print filereleaseapk
                filename1 = os.path.splitext(filename)[0]
                toPath1 = toPath_release + path2 + '/' + filename1 + "-" + version + "-" + time + ".apk"
                # print toPath1
                shutil.copyfile(filereleaseapk, toPath1)
                # print filereleaseapk
            if fnmatch.fnmatch(filename, "*debug.apk"):
                filedebugapk = filedir + "/" + filename
                aapt = os.popen("aapt d badging " + filedebugapk)
                s = aapt.read()
                pattern = re.compile("versionName='(.*)\.(.*)\.(.*).*'", re.I)
                re1 = re.findall(pattern, s)
                version = str(re1[0][0] + "." + re1[0][1] + "." + re1[0][2])
                filename1 = os.path.splitext(filename)[0]
                toPath2 = toPath_debug + path1 + '/' + filename1 + "-" + version + "-" + time + ".apk"
                # toPath2 =toPath + "/debug/" + "Version_debug_" + time+'/' + filename1 + "-" + version + "-" + time+".apk"
                shutil.copyfile(filedebugapk, toPath2)        #shutil模块    拷贝
                # print filedebugapk
                # print filedir
                # print file

print "传输完成!-------------------------!"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值