Python中实现从目录中过滤出指定文件类型的文件,
Python中实现从目录中过滤出指定文件类型的文件,
最近学习下python,将从指定目录中过滤出指定文件类型的文件输出的方法总结一下,供日后查阅
复制代码 代码如下:
#!/usr/bin/env python
import glob
import os
os.chdir(“./”)
for file in glob.glob(“*.py”):
print file
print “#######Another One##########”
for file in os.listdir(“./”):
if file.endswith(“.py”):
print file
print “#######Another Two##########”
for root, dirs, files in os.walk(“./”):
for file in files:
if file.endswith(“.py”):
print os.path.join(root, file)
print “#######Another Three##########”
os.chdir(“./”)
filename_arr={}
i=0
for files in glob.glob(“*.py”):
filename_arr[i] = files
i += 1
for key, value in filename_arr.items():
print key, value
相关内容
- Python Sleep休眠函数使用简单实例,pythonsleep
- Python列表(list)常用操作方法小结,pythonlist
- Python中用pycurl监控http响应时间脚本分享,pythonpycurl
- 理解Python中的With语句,pythonwith语句
- Python写的服务监控程序实例,python监控程序实例
- Python中使用Boolean操作符做真值测试实例,pythonboolean
- Python中的作用域规则详解,python域规则详解
- Python的类实例属性访问规则探讨,python实例
- Python是编译运行的验证方法,python编译
- 用python 制作图片转pdf工具,
评论关闭