Have you ever wanted to work your way through folders and subfolders programmatically? This tutorial will show you how to loop through folders and subfolders using Python and return the list of files. To iterate over all files in a directory (incl. subdirectories), we only need ONE LINE of code. In particular, we will be using Python's Pathlib module. Pathlib comes by default with Python 3.4 and above.
Additionally, I will show you some practical use-cases, such as merging many Excel files into one master file and manipulating Excel workbooks in bulk.
from pathlib import Path
INPUT_DIR = Path.cwd() / "Your_Folder_Name"
for file in list(INPUT_DIR.rglob("*.xls*")):
# Do something
I've developed some handy Excel add-ins that you might find useful:
- 📊 Dashboard Add-in: Easily create interactive and visually appealing dashboards.
- 🎨 Cartoon Charts Add-In: Create engaging and fun cartoon-style charts.
- 🤪 Emoji Add-in: Add a touch of fun to your spreadsheets with emojis.
- 🛠️ MyToolBelt Add-in: A versatile toolbelt for Excel, featuring:
- Creation of Pandas DataFrames and Jupyter Notebooks from Excel ranges
- ChatGPT integration for advanced data analysis
- And much more!
- 📺 YouTube: CodingIsFun
- 🌐 Website: PythonAndVBA
- 💬 Discord: Join the Community
- 💼 LinkedIn: Sven Bosau
- 📸 Instagram: sven_bosau
If you appreciate the project and wish to encourage its continued development, consider supporting my work.
For feedback, suggestions, or potential collaboration opportunities, reach out at [email protected].