A Python CLI tool to count lines in files and directories with powerful filtering options, tree view support, and detailed statistics.
- 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
- Clone the repository:
git clone https://github.com/yourusername/PyLineCounter.git
cd PyLineCounter- No additional dependencies required - uses Python standard library only!
Run the script using Python:
python main.py [path] [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
-
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
.
├── main.py # Entry point and CLI argument handling
├── core/
│ ├── counter.py # Core counting functionality
│ └── utils.py # Utility functions for output formatting
└── README.md
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.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the amirhossein.zip License - see the LICENSE file for details.