'''
栈模拟递归遍历目录(深度遍历)
'''
import os

fileStack = []


def getFile(dirPath):
    global fileStack
    flist = os.listdir(dirPath)
    for name in flist:
        # 获得完整路径
        filepath = dirPath + "/" + name
        # print(filepath)
        # 判读是否是文件夹
        if os.path.isdir(filepath):
            getFile(filepath)
        else:
            fileStack.append(filepath)


if __name__ == '__main__':
    getFile(r"C:\Users\Administrator\Desktop\my\szpython1801\w3")
    while fileStack:
        print(fileStack.pop())

results matching ""

    No results matching ""