vendredi 8 mai 2015

Python delete selected files from a directory [duplicate]

This question is an exact duplicate of:

I want to remove only unwanted files from directory using python. There are files like 1_x.dat, 1_y.dat, 2_x.dat, 2_y.dat,...50_x.dat, 50_y.dat present in my working directory. Now I want to delete only 1*, 2*, 3*, 6*, 8* and 30* files. I ran following script from my working directory

import os
num=[1,2,3,6,8,30]
num=" ".join(str(x)+'*' for x in num)
os.remove(num)

but it complaining

OSError: [Errno 2] No such file or directory: '1* 2* 3* 6* 8* 30*'

Your any help will be appreciated.

Thanks

-Viral

Aucun commentaire:

Enregistrer un commentaire