python遍历文件夹目录代码

import os
def dirf(path,depth = 0):
path = os.path.abspath(path)
files=os.listdir(path)
for f in files:
print(’ '2depth,f)
f = os.path.join(path,f)
if os.path.isdir(f):
dirf(f,depth +=1)

来自七月在线课程:https://www.julyedu.com/course/getDetail/130/1qr54GS0WPKCHeT8ePifXzLG
os.getcwd():获取当前目录

猜你喜欢

转载自blog.csdn.net/weixin_43055882/article/details/89101691
今日推荐