阿里巴巴测开(编程题)-输出目录下的文件(如果是目录要输出目录下的文件)

循环方法:

import os
def allfile(basepath):
    for item in os.path.listdir(basepath):
        path = os.path.join(basepath, item)
        if os.path.isfile(path):
            print item
        else:
            allfile(path)

不循环方法:

import os

for dirpath, dirnames, filenames in os.walk(basepath):
   
    for filename in filenames:
        print(filename)

 

posted @ 2021-01-25 21:47  蒋励  阅读(95)  评论(0编辑  收藏  举报