批量删除当前目录下后缀为.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)

相关文章:

  • 2021-11-05
  • 2021-12-09
  • 2021-10-04
  • 2021-12-19
  • 2021-10-29
  • 2021-10-19
  • 2018-09-14
  • 2021-08-13
猜你喜欢
  • 2021-11-13
  • 2021-10-04
  • 2021-11-06
  • 2021-11-06
  • 2021-11-06
  • 2021-11-05
  • 2021-12-09
  • 2022-01-07
相关资源
相似解决方案