https://stackoverflow.com/questions/3964681/find-all-files-in-a-directory-with-extension-txt-in-python

You can use glob:

import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
print(file)

or simply os.listdir:

import os
for file in os.listdir("/mydir"):
if file.endswith(".txt"):
print(os.path.join("/mydir", file))

or if you want to traverse directory, use os.walk:

import os
for root, dirs, files in os.walk("/mydir"):
for file in files:
if file.endswith(".txt"):
print(os.path.join(root, file))

最新文章

  1. [ASP.NET Core] Getting Started
  2. hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)
  3. python递归理解图
  4. 使用nssm在windows服务器上部署nodejs
  5. [游戏模版6] Win32 graph
  6. sql字段类型介绍
  7. 【题解】【BST】【Leetcode】Convert Sorted Array to Binary Search Tree
  8. linux挂载文件
  9. 土地购买 usaco 斜率优化
  10. UIPickerView基本用法
  11. Boxes in a Line
  12. voucer
  13. navigaitonBar的自定义设置
  14. Extjs 4.0 Tab页
  15. cocos creator主程入门教程(三)—— 资源管理
  16. Python中面向对象的概念(科普)
  17. Matlab - 基础知识
  18. tensorFlow入门实践(一)
  19. WPF备忘录(4)打个勾画个叉娱乐下
  20. Asp.net 用户控件和自定义控件注册

热门文章

  1. linux下软件包的安装方式
  2. c++ 字符串转数字或数字转字符串
  3. OpenCV3 Ref SVM : cv::ml::SVM Class Reference
  4. EUI库 - 自动布局
  5. jetty启动项目后js修改后无法保存
  6. DevOps元数据管理
  7. 尝试用kotlin做一个app(二)
  8. hdu1312题解
  9. CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)
  10. LeetCode——221. 最大正方形