python findAllfile

import os

def findAllfile(path, allfile):
    filelist =  os.listdir(path)  
    for filename in filelist:  
        filepath = os.path.join(path, filename) 
        # print(filepath) 
        if os.path.isdir(filepath):
            # print(filepath)  
            findAllfile(filepath, allfile)  
        else:  
            allfile.append(filepath) #有目录路径
            # allfile = allfile + "/" + filepath
            # allfile.append(filename) #去掉目录路径 
    return allfile  


inputpath = r"D:\Users"
filelist = []
filelist = findAllfile(inputpath, filelist)#find all file

for filesrc in filelist: 
    print(filesrc)

 

posted on 2024-10-03 10:35  Maddock  阅读(3)  评论(0编辑  收藏  举报

导航