@@ -0,0 +1,1402 @@
+#! python3%0A# backupToZip.py - Copies an entire folder and its contents into%0A# a ZIP file whose filename increments.%0A%0Aimport zipfile, os%0A%0Adef backupToZip(folder):%0A    # Backup the entire contents of %22folder%22 into a ZIP file.%0A%0A    folder = os.path.abspath(folder)  # make sure folder is absolute%0A%0A    # Figure out the filename this code should use based on%0A    # what files already exist.%0A    number = 1%0A    while True:%0A        zipFilename = os.path.basename(folder) + '_' + str(number) + '.zip'%0A        if not os.path.exists(zipFilename):%0A            break%0A        number = number + 1%0A%0A    # Create the ZIP file.%0A    print('Creating %25s...' %25 (zipFilename))%0A    backupZip = zipfile.ZipFile(zipFilename, 'w')%0A%0A    # Walk the entire folder tree and compress the files in each folder.%0A    for foldername, subfolders, filenames in os.walk(folder):%0A        print('Adding files in %25s...' %25 (foldername))%0A        # Add the current folder to the ZIP file.%0A        backupZip.write(foldername)%0A        # Add all the files in this folder to the ZIP file.%0A        for filename in filenames:%0A            newBase = os.path.basename(folder) + '_'%0A            if filename.startswith(newBase) and filename.endswith('.zip'):%0A                continue  # don't back up the backup ZIP files%0A            backupZip.write(os.path.join(foldername, filename))%0A    backupZip.close()%0A    print('Done.')%0A%0A%0AbackupToZip('./delicious')%0A

Initialize P05_backupToZip