七
31
海盗日志
评论关闭
Python 中列出目录中所有文件
最近正在想使用Python列出目录中所有文件的方法,因为感觉php的执行起来没有python简单,效率高
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #/usr/bin/python #Filename: readdir.py import string, os, sys dir = '/var' print '----------- no sub dir' files = os.listdir(dir) for f in files: print dir + os.sep + f print '----------- all dir' for root, dirs, files in os.walk(dir): for name in files: print os.path.join(root, name) |
来自:http://www.pythonid.com/html/fenleiwenzhang/normalproblem/20070910/172.html
更多Python学习教程
python天天进步(1)–sys.argv[]用法
Comments are closed.