python 遍历整个目录的文件
相当于shell中的tree
编写python3 脚本
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# **********************************************************
# * Author : James liu
# * Email : ybooks.liu@gmail.com
# * Create time : 2019-05-04 22:28
# * Last modified : 2019-05-04 22:28
# * Filename : walkPathTree.py
# * Description : 遍历目录
# **********************************************************
import os
for folerName, subfolders, filenames in os.walk('/SHELL'):
print('当前目录是:' + folerName)
for subfolder in subfolders:
print("子目录是:" + subfolder)
for filename in filenames:
print("文件索引:" + folerName + ':' + filename)
print('')
网友评论