ich bin absoluter Neuling was Python angeht und wollte zur Übung ein kleines Programm schreiben welches Dateien in einem Zip-Ordner archiviert.
Code: Alles auswählen
#!/usr/bin/python
# Filename: Zip.py
import os
import zipfile
import time
source = input('Enter directory of the file you want to archive:')
target_dir = 'I:\\TestBackup'
today = target_dir + os.sep + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')
comment = input('Enter a comment --> ')
if len(comment) == 0:
target = today + os.sep + now + '.zip'
else:
target = today + os.sep + now + '_' + \
comment.replace(' ', '_') + '.zip'
if not os.path.exists(today):
os.mkdir(today) # make directory
print('Successfully created directory', today)
myZip=zipfile.ZipFile(target, mode='a')
myZip.write(source, arcname=None)
myZip.close()
Die Lösung ist wahrscheinlich banal, aber da ich leider keine Lösung finde, ist die Frage hoffentlich berechtig.
Vielen Dank für eure Hilfe!
Liebe Grüße,
Thison