#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Filename: ddup.py
from os import sep, mkdir, path, mkdir, system
from time import strftime
def main():
# 1. The files and directories to be backed up are specified in a list/string.
src_dir = r'C:\Users\SY\Desktop'
# 2. The backup must be stored in a main backup directory.
dest_dir = r'E:\SY\DesktopBackup'
# 3. The files are backed up into a zip file.
# 4. The current day is the name of the subdirectory in the main directory.
today = dest_dir + sep + strftime('%Y%m%d')
# Create the subdirectory if it isn't already there.
if not path.exists(today):
mkdir(today) # Make directory.
# The current time is the name of the zip archive.
now = strftime('%H%M%S')
# Take a comment from the user to create the name of the zip file.
comment = input('Enter a comment --> ')
comment = comment.strip()
if len(comment) == 0: # Check if a comment was entered.
target_file = today + sep + now + '.zip'
else:
target_file = today + sep + now + '_' + comment.replace(' ', '_') + '.zip'
# 5. We use the zip command (in Windows) to put the files in a zip archive.
zip_exe = r'D:\程序\7-Zip\7z.exe'
zip_command = zip_exe + ' a %s %s' % (target_file, src_dir)
if system(zip_command) == 0:
print('Successful backup to %s.' % target_file)
else:
print('Backup FAILED.')
input('Press any key to exit.')
if __name__ == '__main__':
main()
使用7-zip备份我的桌面(版本三)
最新推荐文章于 2024-03-08 17:43:08 发布