import os # --- Programm um alle Dateien zu durchlaufen--- # Pfad anpassen folder_to_check = 'C:/ordner/wo/alles/liegt/' #Achtung: Forward slashes oder ein r vor dem String def get_directory_size(start_path): total_size = 0 # os.walk() generates the file names in a directory tree # It yields a 3-tuple (dirpath, dirnames, filenames) for dirpath, dirnames, filenames in os.walk(start_path): for f in filenames: # Join the directory path and file name to get the full path fp = os.path.join(dirpath, f) print(fp) # Skip if it is a symbolic link (optional, but good practice) if not os.path.islink(fp): total_size += os.path.getsize(fp) return total_size print(f"Berechne Grösse für: {os.path.abspath(folder_to_check)}") size_in_bytes = get_directory_size(folder_to_check) # Convert to Megabytes for easier reading size_in_mb = size_in_bytes / (1024 * 1024) print(f"Gesamtgrösse: {size_in_bytes} bytes") print(f"Gesamtgrösse: {size_in_mb:.2f} MB")