import os
# 获取文件名
file_names = os.listdir("./data/")
print(file_names)
# 文件名拼接路径
file_list = [os.path.join("./data/",file) for file in file_names]
print(file_list)
代码显示
['01.txt', '02.txt', '03.txt', '04.txt', '05.txt'] ['./data/01.txt', './data/02.txt', './data/03.txt', './data/04.txt','./data/05.txt']