Python 3 OS Module Script to Remove all Files in a Directory With a Specific Extension Full Project For Beginners

You are currently viewing Python 3 OS Module Script to Remove all Files in a Directory With a Specific Extension Full Project For Beginners

 

Welcome folks today in this blog post we will be removing all files with a specific extension using os module in python. All the full source code of the application is given below.

 

 

Get Started

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

app.py

 

 

 

Now as you can see inside my directory uploads we have lots of different extensions files as shown below

 

 

So here in the above script we are only matching the .txt files and deleting it so if you execute this script by typing the below command as shown below

 

python app.py

 

 

So as you can see all the .txt files were deleted using this python script

Leave a Reply