How to delete a file by extension in Python?

后端 未结 5 1178
傲寒
傲寒 2020-12-15 04:36

I was messing around just trying to make a script that deletes items by \".zip\" extension.

import sys
import os
from os import listdir

test=os.listdir(\"/U         


        
5条回答
  •  一生所求
    2020-12-15 04:59

    Prepend the directory to the filename

    os.remove("/Users/ben/downloads/" + item)
    

    EDIT: or change the current working directory using os.chdir.

提交回复
热议问题