ich schreibe hier gerade an einer Funktion die es mir ermöglicht den Inhalt eines Ordners in einen anderen zu kopieren. Das Ganze funktioniert soweit, allerdings erscheint mir meine Variante mit der Unterscheidung von Ordner und Datei bei jedem Vorgang sehr umständlich. Ist euch hier eine einfachere Lösung bekannt? Ich bin noch neu in der Programmiererei und versuche mich etwas einzuarbeiten
Code: Alles auswählen
def copy(path_to_copy_from, path_to_copy_to):
#
#Kopiert alle Ordner und Dateien von von "path_to_copy_from" nach "path_to_copy_to"
#
print ('Kopiere ' + path_to_copy_from + ' nach ' + path_to_copy_to)
for name in os.listdir(path_to_copy_from):
try:
data_now = os.path.join(path_to_copy_from, name)
if os.path.isdir(data_now):
data_in = os.path.join(path_to_copy_from, name)
data_out = os.path.join(path_to_copy_to, name)
shutil.copytree(data_in, data_out)
else:
data_in = os.path.join(path_to_copy_from, name)
data_out = os.path.join(path_to_copy_to, name)
shutil.copy(data_in, data_out)
except shutil.Error as error:
print ('Ein Fehler ist aufgetreten: ' + e)