loading...
Cover image for Analyze directory with Python

Analyze directory with Python

stokry profile image Stokry ・1 min read

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

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()

You can run this with this command

folderstats your_folder_path/  -p -i -v -o final.csv

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.

Posted on by:

stokry profile

Stokry

@stokry

UX developer who falls in love with Python code and advanced algorithms.

Discussion

pic
Editor guide