DEV Community

Cover image for Analyze directory with Python
Stokry
Stokry

Posted on

1 2

Analyze directory with Python

Today I want to show you a cool Python module that creates statistics from a folder structure.

Folderstats is a python module and command-line interface that creates statistics from a folder structure. It returns a Pandas dataframe from the folders and files from a selected folder.

You can install via pip:

pip install folderstats
Enter fullscreen mode Exit fullscreen mode

To get statistics of a folder structure as a Pandas dataframe in Python you can type:

import folderstats
df = folderstats.folderstats('your_folder_path',  ignore_hidden=True)
df.head()
Enter fullscreen mode Exit fullscreen mode

You can run this with this command

folderstats your_folder_path/  -p -i -v -o final.csv
Enter fullscreen mode Exit fullscreen mode

In this case the -i argument makes sure that hidden files (starting with a dot like the .git folder or .gitignore) are ignored, -p includes the id of files and folders and the parent ids which can be used to build a graph and finally -v is responsible for a verbose output for some feedback while running.

Final output looks like this:
enter image description here
Thank you all.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay