From 4ce64c62ea8fed4c33b24e74b355cb7438beb8df Mon Sep 17 00:00:00 2001 From: arceuzvx Date: Fri, 10 Oct 2025 12:54:48 +0530 Subject: [PATCH 1/6] Added my disk visualizer --- Disk Usage Visualizer/README.md | 28 +++++++++++++ Disk Usage Visualizer/disk_visualizer.py | 52 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 Disk Usage Visualizer/README.md create mode 100644 Disk Usage Visualizer/disk_visualizer.py diff --git a/Disk Usage Visualizer/README.md b/Disk Usage Visualizer/README.md new file mode 100644 index 00000000..ac4ea61f --- /dev/null +++ b/Disk Usage Visualizer/README.md @@ -0,0 +1,28 @@ +# Disk Usage Visualizer (CLI) + +A simple Python script that scans directories and displays the largest folders or files by disk usage — right from your terminal. +Lightweight, fast, and cross-platform (works on Linux, macOS, and Windows). + +## Features + +- Recursively analyzes disk usage in a directory + +- Displays top N largest folders (default: 10) + +- Handles long file paths and permission errors gracefully + +- Works seamlessly on Windows, Linux, and macOS + +## Usage + +```bash +# Analyze current directory +python vis.py + +# Analyze a specific path +python vis.py D:\Projects # Windows +python vis.py /home/user/docs # Linux/macOS + +# Show top 20 largest folders +python vis.py . -n 20 +``` diff --git a/Disk Usage Visualizer/disk_visualizer.py b/Disk Usage Visualizer/disk_visualizer.py new file mode 100644 index 00000000..09faf66f --- /dev/null +++ b/Disk Usage Visualizer/disk_visualizer.py @@ -0,0 +1,52 @@ +import os + +def get_dir_sizes(path="."): + dir_sizes = {} + for root, dirs, files in os.walk(path): + for name in files: + try: + full_path = os.path.join(root, name) + + # Handle long paths in Windows + if os.name == "nt": + full_path = r"\\?\\" + os.path.abspath(full_path) + + size = os.path.getsize(full_path) + dir_name = os.path.relpath(root, path) + dir_sizes[dir_name] = dir_sizes.get(dir_name, 0) + size + except (FileNotFoundError, PermissionError, OSError): + continue + return dir_sizes + + +def main(): + import argparse + parser = argparse.ArgumentParser(description="Disk Usage Visualizer (CLI)") + parser.add_argument("path", nargs="?", default=".", help="Path to analyze") + parser.add_argument( + "-n", "--top", type=int, default=10, help="Show top N largest directories" + ) + args = parser.parse_args() + + print(f"Analyzing disk usage in: {args.path}\n") + + dir_sizes = get_dir_sizes(args.path) + + # Sort by size (descending) + sorted_dirs = sorted(dir_sizes.items(), key=lambda x: x[1], reverse=True) + + print(f"Top {args.top} largest directories:") + print("-" * 60) + print(f"{'Directory':40s} | {'Size (MB)':>10s}") + print("-" * 60) + + for dir_name, size in sorted_dirs[: args.top]: + size_mb = size / (1024 * 1024) + print(f"{dir_name:40s} | {size_mb:10.2f}") + + print("-" * 60) + print("✅ Disk usage analysis complete.") + + +if __name__ == "__main__": + main() From b979c536cb79b851836aa25cd86521454a491438 Mon Sep 17 00:00:00 2001 From: Shreya Dutta <136884688+arceuzvx@users.noreply.github.com> Date: Fri, 10 Oct 2025 13:00:25 +0530 Subject: [PATCH 2/6] Update README.md Added my Disk Usage Visualizer to the list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d2635b7e..58db7ffc 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ More information on contributing and the general code of conduct for discussion | CSV_TO_NDJSON | [CSV to Excel](https://github.com/DhanushNehru/Python-Scripts/tree/main/CSV_TO_NDJSON) | A Python script to convert a CSV to an NDJSON files file. | | Currency Script | [Currency Script](https://github.com/DhanushNehru/Python-Scripts/tree/main/Currency%20Script) | A Python script to convert the currency of one country to that of another. | | Digital Clock | [Digital Clock](https://github.com/DhanushNehru/Python-Scripts/tree/main/Digital%20Clock) | A Python script to preview a digital clock in the terminal. | +| Disk Usage Visualizer | [Disk Usage Visualizer](https://github.com/DhanushNehru/Python-Scripts/tree/main/Disk%20Usage%20Visualizer) | A Python Script to display the top N files taking up space in your disk. | Display Popup Window | [Display Popup Window](https://github.com/DhanushNehru/Python-Scripts/tree/main/Display%20Popup%20Window) | A Python script to preview a GUI interface to the user. | | Distance Calculator | [Distance Calculator](https://github.com/Mathdallas-code/Python-Scripts/tree/main/Distance%20Calculator) | A Python script to calculate the distance between two points. | Duplicate Finder | [Duplicate Finder](https://github.com/DhanushNehru/Python-Scripts/tree/main/Duplicate%Fnder) | The script identifies duplicate files by MD5 hash and allows deletion or relocation. | From 1315cd3d19576821f247b4a68fa01532403628c4 Mon Sep 17 00:00:00 2001 From: Shreya Dutta <136884688+arceuzvx@users.noreply.github.com> Date: Sat, 11 Oct 2025 02:04:31 +0530 Subject: [PATCH 3/6] Update Disk Usage Visualizer/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Disk Usage Visualizer/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Disk Usage Visualizer/README.md b/Disk Usage Visualizer/README.md index ac4ea61f..a2c80bc5 100644 --- a/Disk Usage Visualizer/README.md +++ b/Disk Usage Visualizer/README.md @@ -17,12 +17,12 @@ Lightweight, fast, and cross-platform (works on Linux, macOS, and Windows). ```bash # Analyze current directory -python vis.py +python disk_visualizer.py # Analyze a specific path -python vis.py D:\Projects # Windows -python vis.py /home/user/docs # Linux/macOS +python disk_visualizer.py D:\Projects # Windows +python disk_visualizer.py /home/user/docs # Linux/macOS # Show top 20 largest folders -python vis.py . -n 20 +python disk_visualizer.py . -n 20 ``` From dd329d5f74869967edf244cc0c9b94c23d2b0cb4 Mon Sep 17 00:00:00 2001 From: Shreya Dutta <136884688+arceuzvx@users.noreply.github.com> Date: Sat, 11 Oct 2025 12:26:31 +0530 Subject: [PATCH 4/6] removed extra space in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 58db7ffc..fbed8bb5 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ More information on contributing and the general code of conduct for discussion | CSV_TO_NDJSON | [CSV to Excel](https://github.com/DhanushNehru/Python-Scripts/tree/main/CSV_TO_NDJSON) | A Python script to convert a CSV to an NDJSON files file. | | Currency Script | [Currency Script](https://github.com/DhanushNehru/Python-Scripts/tree/main/Currency%20Script) | A Python script to convert the currency of one country to that of another. | | Digital Clock | [Digital Clock](https://github.com/DhanushNehru/Python-Scripts/tree/main/Digital%20Clock) | A Python script to preview a digital clock in the terminal. | -| Disk Usage Visualizer | [Disk Usage Visualizer](https://github.com/DhanushNehru/Python-Scripts/tree/main/Disk%20Usage%20Visualizer) | A Python Script to display the top N files taking up space in your disk. +| Disk Usage Visualizer | [Disk Usage Visualizer](https://github.com/DhanushNehru/Python-Scripts/tree/main/Disk%20Usage%20Visualizer) | A Python Script to display the top N files taking up space in your disk. | Display Popup Window | [Display Popup Window](https://github.com/DhanushNehru/Python-Scripts/tree/main/Display%20Popup%20Window) | A Python script to preview a GUI interface to the user. | | Distance Calculator | [Distance Calculator](https://github.com/Mathdallas-code/Python-Scripts/tree/main/Distance%20Calculator) | A Python script to calculate the distance between two points. | Duplicate Finder | [Duplicate Finder](https://github.com/DhanushNehru/Python-Scripts/tree/main/Duplicate%Fnder) | The script identifies duplicate files by MD5 hash and allows deletion or relocation. | From 3b3e49e9af7ed249352e200ac21feab8c15388f2 Mon Sep 17 00:00:00 2001 From: Shreya Dutta <136884688+arceuzvx@users.noreply.github.com> Date: Sat, 11 Oct 2025 12:29:45 +0530 Subject: [PATCH 5/6] Updated variable name --- Disk Usage Visualizer/disk_visualizer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Disk Usage Visualizer/disk_visualizer.py b/Disk Usage Visualizer/disk_visualizer.py index 09faf66f..053e170f 100644 --- a/Disk Usage Visualizer/disk_visualizer.py +++ b/Disk Usage Visualizer/disk_visualizer.py @@ -12,8 +12,8 @@ def get_dir_sizes(path="."): full_path = r"\\?\\" + os.path.abspath(full_path) size = os.path.getsize(full_path) - dir_name = os.path.relpath(root, path) - dir_sizes[dir_name] = dir_sizes.get(dir_name, 0) + size + dir_path = os.path.relpath(root, path) + dir_sizes[dir_path] = dir_sizes.get(dir_path, 0) + size except (FileNotFoundError, PermissionError, OSError): continue return dir_sizes @@ -40,9 +40,9 @@ def main(): print(f"{'Directory':40s} | {'Size (MB)':>10s}") print("-" * 60) - for dir_name, size in sorted_dirs[: args.top]: + for dir_path, size in sorted_dirs[: args.top]: size_mb = size / (1024 * 1024) - print(f"{dir_name:40s} | {size_mb:10.2f}") + print(f"{dir_path:40s} | {size_mb:10.2f}") print("-" * 60) print("✅ Disk usage analysis complete.") From 97652f5569e17a967260bb2989dffa12417421a7 Mon Sep 17 00:00:00 2001 From: Dhanush Date: Sat, 11 Oct 2025 12:32:07 +0530 Subject: [PATCH 6/6] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fbed8bb5..9065422b 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ More information on contributing and the general code of conduct for discussion | CSV_TO_NDJSON | [CSV to Excel](https://github.com/DhanushNehru/Python-Scripts/tree/main/CSV_TO_NDJSON) | A Python script to convert a CSV to an NDJSON files file. | | Currency Script | [Currency Script](https://github.com/DhanushNehru/Python-Scripts/tree/main/Currency%20Script) | A Python script to convert the currency of one country to that of another. | | Digital Clock | [Digital Clock](https://github.com/DhanushNehru/Python-Scripts/tree/main/Digital%20Clock) | A Python script to preview a digital clock in the terminal. | -| Disk Usage Visualizer | [Disk Usage Visualizer](https://github.com/DhanushNehru/Python-Scripts/tree/main/Disk%20Usage%20Visualizer) | A Python Script to display the top N files taking up space in your disk. +| Disk Usage Visualizer | [Disk Usage Visualizer](https://github.com/DhanushNehru/Python-Scripts/tree/main/Disk%20Usage%20Visualizer) | A Python script to display the top N directories taking up space in your disk. | Display Popup Window | [Display Popup Window](https://github.com/DhanushNehru/Python-Scripts/tree/main/Display%20Popup%20Window) | A Python script to preview a GUI interface to the user. | | Distance Calculator | [Distance Calculator](https://github.com/Mathdallas-code/Python-Scripts/tree/main/Distance%20Calculator) | A Python script to calculate the distance between two points. | Duplicate Finder | [Duplicate Finder](https://github.com/DhanushNehru/Python-Scripts/tree/main/Duplicate%Fnder) | The script identifies duplicate files by MD5 hash and allows deletion or relocation. |