批量删除当前目录下后缀为.txt的文件

a = os.getcwd()
b = os.listdir()
for i in b:
    # 分割路径,返回路径名和文件扩展名的元组
    ext = os.path.splitext(i)
    if ext[1] == '.txt':
        file = os.path.join(a, i)
        os.remove(file)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2021-07-21
  • 2021-12-23
  • 2021-11-22
  • 2022-03-10
猜你喜欢
  • 2021-06-22
  • 2022-01-01
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
相关资源
相似解决方案