Python Script for Recursively Deleting Excel Files in a Directory
Designed for Pakistani Women facing inflation and economic crises.

Python Script for Recursively Deleting Excel Files in a Directory

The objective of this Python code is to recursively traverse through a specified directory and delete all files with the .xlsx extension.


Click here to get Python Code


The objective of this code achieves this by performing the following steps:

  • Imports the os module, enabling interaction with the operating system.
  • Sets the working_directory variable to a specific file path.
  • Utilizes a recursive loop (using os.walk) to navigate through all subdirectories and files within working_directory.
  • For each file encountered, checks if its filename ends with .xlsx, identifying it as an Excel file.
  • If an Excel file is found, it is deleted from its respective location.


Article content
After executing the Python script, both the Excel file in the main folder and its sub-folder were deleted, as per requirements.

Article content


To view or add a comment, sign in

More articles by Umer Saeed

Insights from the community

Others also viewed

Explore topics