您的位置:首页 > 编程语言 > Python开发

python文件目录读取操作

2017-02-27 19:52 309 查看
#coding=utf8

import os

for x in os.listdir('.'): 
if os.path.isfile(x) and os.path.splitext(x)[1]=='.txt':
print(x)
if os.path.isdir(x):
for y in os.listdir(x):
#print(os.path.isfile(os.path.join(x,y)))
#print(os.path.splitext(y)[1])
if os.path.splitext(y)[1]=='.txt':
print (os.path.join(x,y))

'''for x in os.listdir('.'):
if os.path.isfile(x) and os.path.splitext(x)[1]=='.txt':
print(x)

'''
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python
相关文章推荐