import os

def printmulu(path):
    # 获取文件夹中的文件及文件夹
    listdir=os.listdir(path)
    #遍历打印listdir中的文件及文件夹
    for i in listdir:
        # 路径拼接
        tempPath=os.path.join(path,i)
        # 判断listdir中元素是文件夹
        if  os.path.isdir(tempPath):
            print("**文件夹:%s"%i)
        # 判断listdir中元素是文件
        if os.path.isfile(tempPath):
            print("****文件:%s" % i)
    for j in listdir:
        tempPath=os.path.join(path,j)
        if os.path.isdir(tempPath):# 如果还是文件夹 递归遍历
            print('<%s>文件夹中-->'%j)
            printmulu(os.path.join(tempPath))
        else:
            continue

if __name__=="__main__":
    printmulu(r'G:\Python\Python\Day')#如需自己测试,自行改动路径

 

相关文章:

  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2021-11-24
相关资源
相似解决方案