美文网首页
Python学习笔记03——遍历文件夹目录

Python学习笔记03——遍历文件夹目录

作者: 远航天下 | 来源:发表于2018-07-24 22:26 被阅读0次
代码如下:
author = 'damao'

import os

path = r'C:\Python36' # 将要被查找的文件路径
file = []
for file_path,dir_name,file_name in os.walk(path):
    print(file_path)  # 所有文件夹的路径
    print(dir_name)  # 所有的文件夹名
    print(file_name)  # 所有的文件名
    for i in file_name:
        filename = os.path.join(file_path,i)
        if filename.endswith('.exe'):
            file.append(filename)
for j in file:
    print(j)
运行结果如下:
遍历结果.png

相关文章

网友评论

      本文标题:Python学习笔记03——遍历文件夹目录

      本文链接:https://www.haomeiwen.com/subject/rvqumftx.html