DEV Community

Cover image for Analyze directory with Python
Stokry
Stokry

Posted on

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.

Top comments (0)