Home

Awesome

folderstats

This 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.

Folder Structure Graph

Installation

pip install folderstats

Usage

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

import folderstats  
df = folderstats.folderstats(
    '.', hash_name='md5',
    exclude=["tests", "venv", "__pycache__"],
    ignore_hidden=True)
df
pathnameextensionsizeatimemtimectimefoldernum_filesdepthuidmd5
./folder_structure.pngfolder_structurepng5252392022-01-10 16:08:322020-11-22 19:38:032020-11-22 19:38:03False01000a3cac43de8dd5fc33d7bede1bb1849de
./requirements.txtrequirementstxt142022-01-10 18:37:522022-01-08 17:29:522022-01-08 17:29:52False01000d8e272adf08f0389ef08be879d851df8
./requirements-dev.txtrequirements-devtxt332022-01-10 14:14:502022-01-08 17:54:502022-01-08 17:54:50False0100042c7e7d9bc4620c2c7a12e6bbf8120bb
./README.mdREADMEmd39092022-01-10 18:37:522022-01-10 18:37:342022-01-10 18:37:34False010004339e186a35d77689419e996ee3998dc
./folderstats/__main__.py__main__py33132022-01-10 18:06:032022-01-10 18:05:582022-01-10 18:05:58False1100062652872e08be115495aaf6e9f3a239a
./folderstats/__init__.py__init__py45562022-01-10 18:05:122022-01-10 18:04:562022-01-10 18:04:56False11000f0c8eb98713ddec7a4812a1471384296
./folderstatsfolderstats78692022-01-10 17:10:152022-01-10 17:10:152022-01-10 17:10:15True2.011000
./LICENSELICENSE10732022-01-10 16:08:382020-11-22 19:38:032020-11-22 19:38:03False010001232cbd9eced47e27816f69740ad479d
./setup.pysetuppy19252022-01-10 16:29:322020-11-22 19:38:032020-11-22 19:38:03False0100001d39c60a0b41e6c928a6d3df6085d63
..5441582022-01-10 18:37:002022-01-10 18:37:002022-01-10 18:37:00True8.001000

You can use the same functionality as a command-line interface which can generate files (CSV or JSON) or print the statistics directly into the command line:

folderstats . -c md5 -i -o stats.csv

In order to see the other available arguments, type:

folderstats --help
usage: folderstats [-h] [-o OUTPUT_FILEPATH] [-c HASH_NAME] [-a] [-m] [-i]
                   [-p] [-e EXCLUDE] [-f FILTER_EXTENSION] [-l] [-v]
                   folderpath

Creates statistics from a folder structure

positional arguments:
  folderpath            input folder path

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT_FILEPATH    output filepath, CSV and JSON supported
  -c HASH_NAME          hash function for checksum
  -a                    add absolute path column
  -m                    store timestamps with microseconds
  -i                    ignore hidden files and folders, Linux and Unix only
  -p                    Add index and parent index
  -e EXCLUDE, --exclude EXCLUDE
                        Exclude files and folders by name
  -f FILTER_EXTENSION, --filter-extension FILTER_EXTENSION
                        Filter files by extension
  -l, --follow-links    Follow symbolic and hard links
  -v                    verbose console output

Testing

Prepare dev environment with:

# Create virtual environement
python -m venv ./venv

# Install dependencies
pip install -r requirements-dev.txt
pip install -r requirements.txt

# Activate virtual environment
source venv/bin/activate

To run unit tests, type:

pytest -v

License

This project is licensed under the MIT license. See the LICENSE for details.