Python小记-- 读取当前目录下所有文件名
# -*- coding: utf-8 -*- import os def file_name(file_dir): list = [] ## 空列表 for root, dirs, files in os.walk(file_dir,topdown=True): for name in files: list.append(name) with open("SelectAllFiles.txt","w") as f: for item in list: f.write(item+'\n') f.write(' -t '.join(list)) if __name__=="__main__": file_name(os.getcwd())