Skip to content

AmirhosseinDotZip/PyLineCounter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyLineCounter

A Python CLI tool to count lines in files and directories with powerful filtering options, tree view support, and detailed statistics.

Features

  • Count lines in files and directories recursively
  • Filter files by extension (include or exclude)
  • Display results in tree structure format
  • Show detailed statistics with character counts
  • Control directory traversal depth
  • Ignore empty files option
  • Error handling for inaccessible files

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/PyLineCounter.git
cd PyLineCounter
  1. No additional dependencies required - uses Python standard library only!

Usage

Run the script using Python:

python main.py [path] [options]

Command Line Options

  • path: Directory or file to analyze (default: current directory)
  • -x, --include: Only process files with specified extensions (comma-separated)
  • -e, --exclude: Exclude files with specified extensions (comma-separated)
  • -t, --tree: Show results in tree structure format
  • -v, --verbose: Show detailed output including character counts
  • -d, --depth: Maximum directory depth to traverse
  • --ignore-empty: Skip files with zero lines
  • -o, --output: Save results to specified file

Examples

  • Count lines in current directory:

    python main.py
  • Count lines in specific directory:

    python main.py /path/to/dir
  • Count lines only in Python files:

    python main.py -x py
  • Count lines in Python and JavaScript files:

    python main.py -x py,js
  • Exclude specific file types:

    python main.py -e txt,log
  • Show tree structure with line counts:

    python main.py -t
  • Verbose output with character counts:

    python main.py -v
  • Limit directory depth to 2 levels:

    python main.py -d 2
  • Save output to file:

    python main.py -o output.txt

Project Structure

.
├── main.py           # Entry point and CLI argument handling
├── core/
│   ├── counter.py    # Core counting functionality
│   └── utils.py      # Utility functions for output formatting
└── README.md

Error Handling

The tool gracefully handles various error scenarios:

  • Invalid file paths
  • Permission denied errors
  • Encoding issues
  • Invalid extension filters

Errors are reported in the output without interrupting the overall counting process.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the amirhossein.zip License - see the LICENSE file for details.

About

A lightweight and flexible Python tool for analyzing codebases by counting lines of code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages