A simple Python utility that analyzes files inside a selected folder and displays useful file statistics.
The project uses Python's built-in os module to inspect files, calculate file sizes, identify extensions, and find the largest file.
The goal of this project is to learn how to:
- Work with folders and files
- Use Python's
osmodule - Get file sizes
- Extract file extensions
- Store file information using dictionaries
- Calculate total file size
- Find the largest file
- Build a simple file analysis utility
- 📂 Analyze any folder
- 📊 Count total files
- 💾 Calculate total folder size
- 📄 Display individual file information
- 🔍 Detect file extensions
- 📈 Find the largest file
- ⚡ Uses only Python standard library
- Python
osmodule- Lists
- Dictionaries
- Classes and Objects
max()- Lambda functions
python-file-statistics-analyzer/
│
├── main.py
├── file_analyzer.py
├── README.md
└── .gitignore
The os module allows Python to interact with the operating system.
import osos.path.exists(self.folder)This checks whether the selected folder exists.
os.listdir(self.folder)This returns the names of files and folders inside the selected directory.
os.path.isfile(path)This makes sure that only files are analyzed.
os.path.getsize(path)This returns the file size in bytes.
The project converts bytes into KB:
size / 1024os.path.splitext(name)[1]For example:
main.py → .py
README.md → .md
Each file is stored as a dictionary:
{
"name": name,
"size": size,
"extension": extension
}This makes the file information easy to access.
The largest file is found using:
largest = max(files, key=lambda file: file["size"])max() finds the largest value, while the lambda function tells Python to compare files using their size.
git clone https://github.com/ayushman-ece/python-file-statistics-analyzer.gitcd python-file-statistics-analyzerpython main.pyExample:
.
or:
C:\Users\YourName\Documents
===== FILE STATISTICS =====
Total Files: 4
Total Size : 1.59 KB
===== FILE DETAILS =====
.gitignore → 0.04 KB → No Extension
file_analyzer.py → 1.41 KB → .py
main.py → 0.14 KB → .py
README.md → 0.00 KB → .md
===== LARGEST FILE =====
Name: file_analyzer.py
Size: 1.41 KB
Through this project, I learned:
- File and folder handling
os.listdir()os.path.exists()os.path.isfile()os.path.getsize()os.path.splitext()- Lists
- Dictionaries
- Classes
- Lambda functions
max()- Basic file statistics
Possible future features:
- Analyze subfolders recursively
- Group files by extension
- Find duplicate files
- Find oldest and newest files
- Export statistics to CSV
- Add file-type statistics
- Create a graphical interface
- Add folder size visualization
✅ Completed
This project was built as part of my Python learning journey to improve my understanding of file handling, automation, and data analysis.
Ayushman Tiwari
GitHub: