I wrote code to detect all the .exe files in a directory but instead it deletes everything in the folder. How can I change the code to make it delete only the .exe files?
import os
import shutil
dir_name = "/Users/plapl/Downloads/"
source = os.listdir("/Users/plapl/Downloads/")
for files in source:
if files.endswith(".exe"):
shutil.rmtree(dir_name, files)