1.导入os
import os
2.获取当路径
path = os.getcwd()
3.获取文件数据列表
list_files = os.walk(path)
4.遍历列表获取对应的数据
for dirpath,dirnames,filenames is list_files:print(dirpath) #当前目录的绝对路径print(dirnames) #目录下的所有文件夹print(filenames) #目录下的所有文件for dir in dirnames:all_files.append(os.path.join(dirpath,dir))for name in filenames:all_files.append(os.path.join(dirpath,name))for file in all_files:print(file)