# -*- coding: cp936 -*-
#python 27
#xiaodeng
#查找特定后缀的文件

#方法一:
import os
#os.listdir,获取指定目录下的内容
#返回一个list
#该目录下所有的内容都将被返回

import os
def FileType(fileName,*args):
    for types in args:
        if fileName.endswith(types):return fileName

if __name__ == '__main__':
    listFile = os.listdir('C:\python')#对应要查找的文件目录
    HouZhui=('.txt','.py','.html')#定义需要查找的文件后缀,请带上点号,可定义一个后缀,也可以定义多个
    for fileName in listFile:
        if FileType(fileName,HouZhui)!=None:
            print FileType(fileName,HouZhui)

 


# -*- coding: cp936 -*-
#python 27
#xiaodeng
#查找特定后缀的文件


#方法二
import os
#os.listdir,获取指定目录下的内容
#返回一个list
#该目录下所有的内容都将被返回
listFile = os.listdir('C:\python')
for fileName in listFile:
    fileHtml =fileName.endswith('.html')
    fileTxt=fileName.endswith('.txt')
    if fileHtml or fileTxt:
        print fileName

 

相关文章:

  • 2021-09-05
  • 2021-09-10
  • 2021-06-24
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2021-10-02
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案