import os
def func(path, ceng):
# 打开文件件 ---》拿到文件的名字
last = os.listdir(path)
# print(last)
for name in last: # 拿到每一个文件名字
# 2.判断name对应的是文件夹还是文件
# 获取文件所在的路径
real_path = os.path.join(path, name) # join的作用: 路径+a/文件名
if os.path.isdir(real_path): # 判断文件夹还是文件
print("!--" * ceng + name)
func(real_path, ceng + 1) # 递归的入口
else:
print("!--" * ceng + name)
# 用w打开 里面的内容就被1覆盖了
open(real_path, mode='w').write('111')
func('a', 1)
python_函数递归
最新推荐文章于 2024-10-08 12:37:10 发布