Today we are going to discuss this important topic via this article Python 3 OS Module Script to Remove all Files in a Directory With a Specific Extension. We hope you like this article.

Python 3 OS Module Script to Remove all Files in a Directory With a Specific Extension
import os
dir_name = "uploads"
test = os.listdir(dir_name)
for item in test:
if item.endswith(".txt"):
os.remove(os.path.join(dir_name, item))
Read Also: Python 3 Script to Remove Duplicates Elements From List or Array
Final Words
Python 3 OS Module Script to Remove all Files in a Directory With a Specific Extension We learned about this very clearly through this article. And if you liked this article please share it with your friend.