python 打开文件 通配符_如何使用python和通配符打开目录中的多个文件

我有这些文件来自一个捕捉标志事件,DEFCON 22:balalaikacr3w_00001_20140808100030.cap

balalaikacr3w_00001_20140809100255.cap

mmibh_00115_20140809193255.cap

mmibh_00116_20140808193530.cap

还有更多。团队名称不会更改,但每个团队都有多个文件,范围从00001到00125,并显示在团队名称之后。然后文件还显示日期(Y/M/D)为20140808。改变的是天,而不是年或月。在

我正在寻找一种方法来动态打开每个文件来读取其信息。我在一个目录中也有这些团队。我想用一张外卡得到球队和比赛日。这是我在bash中完成的代码:

^{pr2}$

我需要把它翻译成python,如果可能的话,使用字典。这是我到目前为止的情况。在def main():

teams = {'balalaikacr3w':1,'binja':2,'blue-lotus':3,'codered':4,'dragonsector':5,'gallopsled':6

,'hackingforchimac':7,'hitcon':8,'kaist':9,'mmibh':10,'mslc':11,'oracle':12,'penthackon':13,'ppp':14

,'raon_asrt':15,'reckless':16,'routards':17,'shellphish':18,'stratum':19,'team9447':20,'w3stormz':21}

for key in sorted(teams.iterkeys()):

print (teams[key],": ", key, sep='')

x = str(raw_input("Please enter the name for the team that you would like to see: "))

#print(teams[str(x)]) # trying to get the name value rather than the key

Path = "~/sonomastate/cs496/"

filelist = os.listdir(Path)

for i in filelist:

if i.startswith(teams[str(x)]): # You could also add "and i.startswith('f')

with open(Path + i, 'r') as f:

for line in f:

# Here you can check (with regex, if, or whatever if the keyword is in the document.)

date = {'2014-08-08':1, '2014-08-09':2,'2014-08-10':3}

for key in sorted(date.iterkeys()):

print (date[key],": ", key, sep='')

y = int(input("Please entet the number for the date that you would like to load: "))

parser = argparse.ArgumentParser()

parser.add_argument('--name', type=str, default="balalaikacr3w_00001_20140808100030.cap", help="input file")

args = parser.parse_args()

sys.stdout.write(str(pcap_scan(args)))

输出如下:1: balalaikacr3w

2: binja

3: blue-lotus

4: codered

5: dragonsector

6: gallopsled

7: hackingforchimac

8: hitcon

9: kaist

10: mmibh

Please enter the name for the team that you would like to see:

1: 2014-08-08

2: 2014-08-09

3: 2014-08-10

Please enter the number for the date that you would like to load:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值