Skip to content

Sven-Bo/iterate-over-folders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to Loop Through Folders and Subfolders

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.

Code Snippet

from pathlib import Path
INPUT_DIR = Path.cwd() / "Your_Folder_Name"
for file in list(INPUT_DIR.rglob("*.xls*")):
    # Do something

Video Tutorial

YouTube Video

🤓 Check Out My Excel Add-ins

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!

🤝 Connect with Me

☕ Support

If you appreciate the project and wish to encourage its continued development, consider supporting my work. ko-fi

Feedback & Collaboration

For feedback, suggestions, or potential collaboration opportunities, reach out at [email protected]. Logo

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published