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:
1import os
2import shutil
3
4desktop_path = os.path.expanduser("~/Desktop")
5old_folder_path = os.path.join(desktop_path, "old")
6destination_folder = os.path.join(desktop_path, "new")
7
8if not os.path.exists(destination_folder):
9os.makedirs(destination_folder)
10
11for root, dirs, files in os.walk(old_folder_path):
12for file in files:
13file_path = os.path.join(root, file)
14shutil.copy(file_path, destination_folder)
15
16print(f"All files are copied in '{destination_folder}'")
Published: 2/16/2025