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='.', items_list=None): if items_list is None: items_list = [] try: with os.scandir(path) as entries: for entry in entries: try: if entry.is_file(): size_kb = os.path.getsize(entry.path) / 1024 items_list.append((entry.path, f"{size_kb:.2f} KB")) elif entry.is_dir(): # Show directory name with <DIR> tag items_list.append((entry.path + os.sep, "<DIR>")) except (PermissionError, FileNotFoundError): continue except (PermissionError, FileNotFoundError): pass return items_list def save_file_list_as_image(file_data, output_image='file_list.png'): if not file_data: print("No files or folders found.") return fig_height = max(4, len(file_data) * 0.25) fig, ax = plt.subplots(figsize=(14, fig_height)) ax.axis('off') table_data = [("File/Folder Path", "Size/Type")] + 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/folder list screenshot as '{output_image}'") if __name__ == '__main__': directory_path = 'files' # Change this to your target directory file_data = collect_files_with_sizes(directory_path) save_file_list_as_image(file_data) |