import os
def file_display(filepath):
for each in os.listdir(filepath): #得出文件的绝对路径
absolute_path = os.path.join(filepath,each)
is_file = os.path.isfile(absolute_path) #判断文件或目录得出布尔值
if is_file:
print(absolute_path)
else:file_display(absolute_path)
file_display('D:/python') #修改路径
--------------------------------------------------------------------------------
D:\untitled1\venv\Scripts\python.exe D:/untitled1/test.py
D:/python\122.txt
D:/python\新建 DOC 文档.doc
D:/python\新建位图图像.bmp
Python打印出文件夹下的文件(包含路径)
最新推荐文章于 2024-07-20 03:12:30 发布