Simple and Practical Python Tools (Issue 4)

31. File Size Analyzer “`python import os from pathlib import Path def analyze_disk_usage(folder_path, top_n=10): """ Analyze the file sizes in a folder and find the largest files """ file_sizes = [] for file_path in Path(folder_path).rglob('*'): if file_path.is_file(): try: size = file_path.stat().st_size file_sizes.append((file_path, size)) except OSError: continue # Sort by size file_sizes.sort(key=lambda x: x[1], reverse=True) print(f"Folder: … Read more