Dieses Python Skript kopiert alle Dateien aus einem Ordner auf dem Desktop (namens „old“) und verschiebt sie in einen neuen Ordner (namens „new“). Dabei werden alle Unterverzeichnisse innerhalb des Ordners „old“ durchsucht und jede gefundene Datei in den Ordner „new“ kopiert. Falls der Ordner „new“ noch nicht existiert, wird er automatisch erstellt:
import os
import shutil
desktop_path = os.path.expanduser("~/Desktop")
old_folder_path = os.path.join(desktop_path, "old")
destination_folder = os.path.join(desktop_path, "new")
if not os.path.exists(destination_folder):
os.makedirs(destination_folder)
for root, dirs, files in os.walk(old_folder_path):
for file in files:
file_path = os.path.join(root, file)
shutil.copy(file_path, destination_folder)
print(f"All files are copied in '{destination_folder}'")
Published: 2/16/2025