Python 3 Glob Library Script to Delete all Files and Folders Inside a Directory or Folder Full Project For Beginners

Python 3 Glob Library Script to Delete all Files and Folders Inside a Directory or Folder Full Project For Beginners

 

Welcome folks today in this blog post we will be removing all files and folders inside a directory in python using glob 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

 

import os
import glob

files = glob.glob('uploads/*')
for f in files:
    os.remove(f)

 

 

Now here in this script we are importing the built in glob module of python and then we are removing all the contents files and folders inside the directory called as uploads as shown below

See also  Python 3 Tkinter Prepopulate a Text Entry Field With Suggested or Default Text GUI Desktop App Full Project For Beginners

 

 

 

As you can see we have four files inside this directory called as uploads and now If you run this python script by typing the below command as shown below

 

python app.py

 

 

So here as you can see we have removed all the files and folders inside the directory called uploads in python using glob module

 

Leave a Reply