import os
def alldir(path):
stack=[]
stack.append(path)
while len(stack)!=0:
dirpath=stack.pop()
filelist=os.listdir(dirpath)
for filename in filelist:
fileabs=os.path.join(dirpath,filename)
if os.path.isdir(fileabs):
stack.append(fileabs)
print('目录:'+filename)
else:
print('文件:'+filename)
alldir(r'C:\Program Files (x86)')