Python:目录遍历--利用glob模块

#!/usr/bin/env python
# coding:UTF-8


"""
@version: python3.x
@author:曹新健
@contact: [email protected]
@software: PyCharm
@file: glob模块.py
@time: 2018/9/25 23:29
"""

import glob
'''
glob()与iglob()功能相同,只不过iglob返回迭代器,glob返回列表
指定recursive=True时,可以对比任意目录,包括子目录
'''
for file in glob.iglob(r'C:\test\**',recursive=True):
    print(file)


猜你喜欢

转载自blog.csdn.net/caoxinjian423/article/details/84476765