Python脚本 —Windows下文件备份

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37280790/article/details/77507251

Python脚本 —Windows下备份文件【Python 3.6版本】

1:明确备份资源和保存路径
2:Windows下没有安装zip打包软件,需安装info-zip(https://sourceforge.net/projects/infozip/files/)
3:明确zip和.strftime相应指令
4:系统中运行相应指令
#!/usr/bin/python
# Filename: backround.py
import os
import time
source = [r'E:\00_资料\ckj', r'E:\00_资料']
target_dir = r'E:\MyDownloads'
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
print(target)
zip_command = "zip -qr %s %s" % (target,' '.join(source))
print(zip_command)
if os.system(zip_command)== 0:#系统中运行该命令语句
    print('Successful backup to', target)
else:
    print('Backup FAILED ')




猜你喜欢

转载自blog.csdn.net/m0_37280790/article/details/77507251