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

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

operating system - Find and delete file in multiple folders getting an error

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...