I am working on a search-and-destroy type program which I need it to do is search all directories with a certain file-name and append them to a list. after that delete all those files…not objects in list or the list…
import os
file_list=[]
for root, dirs, files in os.walk(path-to-dir'):
for f_name in files:
if f_name.startswith("file-name"):
file_list.append(f_name)
I could write up to appending part of the code but I don’t know next…
Some help please
To remove a file from your computer, use
os.remove(). It takes full path to the file as it’s parameter, so instead of callingos.remove("infectedFile.dll")you would callos.remove("C:/program files/avira/infectedFile.dll")So your
file_listshould contain full paths to the files, and then just call: