python batch output file names in the folder and output to excel

python batch output file names in the folder and output to excel

Effect picture:

 

 Implementation code:

import os
from openpyxl import workbook  # 写入Excel表所用
from openpyxl import load_workbook  # 读取Excel表所用
 
def getfilelist(filepath):
    filelist =  os.listdir(filepath)  # 获取filepath文件夹下的所有的文件
    files = []
    for i in range(len(filelist)):
        child = os.path.join('%s\\%s' % (filepath, filelist[i]))
        # child=filelist[i]
        if os.path.isdir(child):
            file_list=[i.split('\\')[-1].split('.')[0]  for i in getfilelist(child)]
            files.extend(file_list)
        else:
            files.append(child)
    return files
 
 
# filepath = "D:\\Documents\\Desktop\\书籍\\2020论文

Guess you like

Origin blog.csdn.net/babyai996/article/details/122403129