Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to write some code for finding and deleting hidden files in many folders. The file I want to remove is called "desktop". Where do I need to write the file name? I don't know how to continue from this point. Also, I get the error: Illegal target for variable annotation

import os, fnmatch
def find(pattern,path):
    result=[]
    for root, dirs, files in os.walk(path):
        for name in files:
            in fnmatch.fnmatch(name,pattern):
               result.append(os.path.join(root,name))
    return result

res= find('*.ini', r'C:Users...')
print(res)
for file in res:
os.remove(file)
question from:https://stackoverflow.com/questions/65649109/find-and-delete-file-in-multiple-folders-getting-an-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...