Project Line Counter is a lightweight Python command-line utility designed to help developers quickly analyze the size and structure of their codebases. It recursively scans a project directory, counts lines of code across multiple file types, and provides both a total line count and a breakdown by file extension. With options to include or exclude hidden files, skip specific directories or file types, and ignore non-text/binary files, it's a flexible tool for getting a clearer picture of your project's composition without the overhead of a full-featured code metrics suite.
- Scans a directory and its subdirectories
- Supports multiple file extensions (e.g.
.py,.cs,.js,.swift) - Counts all files if no
--extargument is provided - Optionally include hidden files and directories with
--include-hidden - Optionally exclude certain file extensions or directories when counting all files
- Skips unreadable or binary files
- Provides a breakdown of lines by file type
- Reports the number of skipped non-text/binary files
- Python 3.7 or later
This project requires Python 3.8+.
If you don’t already have Python installed, follow the steps below:
- Download the latest stable release from the official Python website.
- Run the installer and make sure to check "Add Python to PATH" before clicking Install Now.
- Verify the installation by opening Command Prompt and running:
python --version
Python 3 usually comes pre-installed on macOS, but it’s often outdated. It’s recommended to install the latest version via Homebrew:
brew install pythonVerify with:
python3 --versionsudo apt update
sudo apt install python3 python3-pipsudo dnf install python3 python3-pipCheck Installation with:
python3 --versionOnce installed, you can manage dependencies with:
pip install -r requirements.txtClone the repository:
git clone https://github.com/ottles91/project-line-counter
cd line-counterBasic usage (count all text-based files in a given directory):
python3 -m LineCounter /path/to/projectCount lines for all Python, Swift and JavaScript files:
python3 -m LineCounter /path/to/project --ext .py .swift .jsCount lines from all files except for .css files:
python3 -m LineCounter /path/to/project --exclude-ext .cssCount all files but skip certain directories:
python3 -m LineCounter /path/to/project --exclude node_modules venvCombine directory and extension exclusion:
python3 -m LineCounter /path/to/project --exclude node_modules build --exclude-ext .txt .jsonInclude hidden files & folders:
python3 -m LineCounter /path/to/project --include-hiddenSee help:
python3 -m LineCounter -hCounting total lines of code in ./my_project...
Total lines of code: 2500
Lines by file type:
.css: 667
.html: 2204
.js: 91
.md: 43
No Extension: 30
Skipped 10 non-text/binary files.
MIT License. Free to use and modify.