python遍历处理_[python]命令行,遍历处理文件夹里的某一类型的文件

# -*- coding: utf-8 -*-

#!/usr/local/bin/python

import os, sys,time,datetime,time,subprocess,pdb,fnmatch

from threading import Thread

def commandline_invoke(command_list):

#stdin_value ="./" + command + " ".join(parameter_list)

stdin_value = command_list

child1 = subprocess.Popen(stdin_value, stdout=subprocess.PIPE)

#print "ExcuteCommand: " + " ".join(stdin_value)

#print "ExcuteResult: "

while True :

line = child1.stdout.readline()

if not line :

break

print line

def translate(fileList):

commandLine = ["./performanceLogAnalyze.pl", "","QQ.app.dSYM"]

for fileName in fileList:

commandLine[1] = fileName

commandline_invoke(commandLine)

def get_dst_files(root,patterns='*' , single_level=False ,yieild_folders= False):

#将模式从字符串中取出放入列表中

patterns = patterns.split(';')

for path ,subdirs ,files in os.walk(root):

if yieild_folders :

files.extend(subdirs)

files.sort()

for name in files:

for pattern in patterns:

if fnmatch.fnmatch(name,pattern):

yield os.path.join(path,name)

break

if single_level:

break

def test_demo_1():

for i in range(0,1):

commandline_invoke(["./performanceLogAnalyze.pl", "BluePerformance.log","QQ.app.dSYM"])

def test_demo_2():

search_path = './'

#/Users/wenlezhou/Desktop/transfer

#只搜索一层目录,single_level=True

#pdb.set_trace()

for path in get_dst_files(search_path,'*.log',True):

print path

def execute_1():

print "把要翻译的blue日志文件,performanceLogAnalyze.pl文件,perforTransBat.py 文件放在同一文件夹下。会翻译所有的.log文件"

fileList = []

search_path = './'

for path in get_dst_files(search_path,'*.log',True):

fileList.append(path)

translate(fileList)

if __name__ == '__main__':

execute_1()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值