效果
# -*- coding: utf-8 -*-
import os
file_path = '.\\'
files_list = []
for root, dirs, files in os.walk(file_path):
# print(root) #當前目錄路徑
# print(dirs) #當前路徑下所有子目錄
# print(files) #當前路徑下所有非目錄子文件
files_list.append(files)
with open('file_name.txt', 'w') as file:
for i in files_list[0]:
file.write(i+'\n')