C:\Users\hm\Desktop\Web>7z a tes.7z python362.chm 7-Zip 17.01 beta (x64) : Copyright (c) 1999-2017 Igor Pavlov : 2017-08-28 Scanning the drive: file, 8010498 bytes (7823 KiB) Creating archive: tes.7z Add new data to archive: 1 file, 8010498 bytes (7823 KiB) Files read from disk: 1 Archive size: 7982833 bytes (7796 KiB) Everything is Ok
#Filename:backup.py
import os,time
#要备份的文件的列表
source = ['C:\\Users\\hm\\Desktop\\Web\\CH2','C:\\Users\\hm\\Desktop\\Web\\CH3']
#构造好备份目标文件
target_dir = 'D:\\backup'
target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S')+'.7z'
#strftime规划了时间的格式,在下面深入了解下这个函数
#构造系统命令行
command = "7z a {0} {1}".format(target,' '.join(source))
#字符串出现空格要用双引号吗?
#print(command)
#使用系统执行命令,执行成功将返回0
if os.system(command) == 0:
print('备份成功至',target)
else:
print('备份失败')
source = [r'C:\Users\hm\Desktop\Web\CH2',r'C:\Users\hm\Desktop\Web\CH3']
备份成功至 D:\backup\20171105151908.7z
>>> import time
>>> print(time.strftime('%b%a'))
NovSun
>>> print(time.strftime('%b %a'))
Nov Sun
>>> print(time.strftime('%b %a %Z'))
Nov Sun 中国标准时间
>>> print(time.strftime('%b %a %p'))
Nov Sun PM
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有