import os
def get_filelist(dir):
for home, dirs, files in os.walk(dir):
print("#######dir list#######")
for dir in dirs:
print(dir)
print("#######dir list#######")

print("#######file list#######")
for filename in files:
print(filename)
fullname = os.path.join(home, filename)
print(fullname)
print("#######file list#######")
if __name__ == "__main__":
#.为遍历当前目录 其他的给绝对路径
get_filelist('.')

Python3遍历指定文件夹下所有文件及文件夹_当前目录