One - One Code All

Blog Content

python获取指定指定后缀的文件名

Python   2008-09-12 20:37:18

获取指定目录下的所有指定后缀的文件名

使用到的函数有:
os.path.splitext():分离文件名与扩展名

#! /usr/bin/python
# -*- coding: utf-8 -*-
 
import os
 
 
def get_file_name(path):
    ''' 获取指定目录下的所有指定后缀的文件名 '''
 
    f_list = os.listdir(path)
        for i in f_list:
        if os.path.splitext(i)[1] == '.txt':
            print i



上一篇:linux内存free命令buffer cache作用
下一篇:shell seq命令详解

The minute you think of giving up, think of the reason why you held on so long.