app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import os import matplotlib.pyplot as plt def collect_files_with_sizes(path='.', files_list=None): if files_list is None: files_list = [] try: with os.scandir(path) as entries: for entry in entries: try: if entry.is_file(): size_mb = os.path.getsize(entry.path) / (1024 * 1024) files_list.append((entry.path, f"{size_mb:.2f} MB")) elif entry.is_dir(): collect_files_with_sizes(entry.path, files_list) except (PermissionError, FileNotFoundError): continue except (PermissionError, FileNotFoundError): pass return files_list def save_file_list_as_image(file_data, output_image='file_list.png'): if not file_data: print("No files found.") return # Adjust height based on number of files fig_height = max(4, len(file_data) * 0.25) fig, ax = plt.subplots(figsize=(14, fig_height)) ax.axis('off') table_data = [("File Path", "Size (MB)")] + file_data table = ax.table(cellText=table_data, loc='center', cellLoc='left', colWidths=[0.75, 0.25]) table.auto_set_font_size(False) table.set_fontsize(9) table.scale(1, 1.2) fig.tight_layout() plt.savefig(output_image, dpi=200) print(f"✅ Saved file list screenshot as '{output_image}'") if __name__ == '__main__': directory_path = 'compressed_output' # Change to target another directory file_data = collect_files_with_sizes(directory_path) save_file_list_as_image(file_data) |