python 如何找到某一目录下的文件类型(三种方法)

时间:2015-10-07 12:00:49   收藏:0   阅读:1842

#!/usr/bin/env python

1 import glob
2 import os
3 os.chdir(“./”)
4 for file in glob.glob(“*.py”):
5     print file

print “#######Another One##########”

import os
for
file in os.listdir(“./”): if file.endswith(“.py”): print file

print “#######Another Two##########”

import os
for
root, dirs, files in os.walk(“./”):   for file in files:     if file.endswith(“.py”):       print os.path.join(root, file)

print “#######Another Three##########”

import os
import glob
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

 

 

来源: <http://www.jb51.net/article/60641.htm>
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!