Record for myself and share with you.

使用函数

  1. os.path.splitext(): 分离文件名与扩展名
  2. os.listdir(path): 列出所有文件

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#! /usr/bin/python
# -*- coding: utf-8 -*-

import os

def getFileName(path):
f_list = os.listdir(path)
for i in f_list:
if os.path.splitext(i)[1] == '.log':
print i


if __name__ == '__main__':

path = '/my/project'
getFileName(path)