Python Delete Files with Specific Extension Example
This post will give you example of python delete files with specific extension. This article will give you simple example of remove files with specific extension python. We will use python delete all images with specific extension. I would like to show you delete all files with extension python. you will do the following things for python remove file by extension.
Sometimes, we need to delete a specific file extension. in this example we will remove only ".png" files from files folder. so let's see below example code.
You can use these examples with python3 (Python 3) version.
let's see below simple example with output:
import os from os import listdir folderPath = 'files/'; # Get All List of Files for fileName in listdir(folderPath): #Check file extension if fileName.endswith('.png'): # Remove File os.remove(folderPath + fileName) print("All .png files removed successfully")
All .png files removed successfully
I hope it can help you...
We are Recommending you
- Python Delete File if Exists Example
- Python Post Request with pem File Example
- Python Post Request with Json File Example
- Python Post Request with Basic Authentication Example
- Python Post Request with Bearer Token Example
- Python Copy File From one Directory to Another Example
- Python Get File Extension from Filename Example
- Python Create Zip Archive from Directory Example
- How to Check if Today is Friday or not in Python?
- Python PATCH Request with Parameters Example
- How to Get Current Time in Python?