lehoso
# -*- coding: utf-8 -*-
# @Author  : LEHOSO
# @FileName: Test.py
# @Time    : 2021/11/4 00:19
# coding=utf-8
import os

dir = \'D:\\xxx\\xxx\'#需要读取的路径
file = os.listdir(dir)
fopen = open(r\'书名.txt\', \'w\', encoding="utf-8")#写入到当前目录,并设置为utf-8字符
for b in file:
    string = b + \'\n\' #每输出一个进行换行 "\n"为转义字符
    line = string.replace(" ", "").replace(".pdf", "") + "\t" #拿到文件名进行数据清洗
    fopen.write(line)#写入到书名.txt文本内
print(len(b)) #输出有多少文件
fopen.close()

分类:

技术点:

相关文章:

  • 2022-02-24
  • 2022-02-19
  • 2021-08-04
  • 2021-12-29
  • 2022-12-23
  • 2022-02-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
  • 2021-03-31
  • 2021-11-16
相关资源
相似解决方案