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())

 

posted @ 2018-02-23 16:15  狂想NICE  阅读(1311)  评论(0编辑  收藏  举报