Python脚本-文件备份

在学习python后,发现它真的太奇妙,什么事儿都能干,这里仅记录下实用的备份文件的小脚本!

#!/usr/bin/python
# -*-coding:utf-8 -*-
import  os
import  time
#需要备份的文件和文件目录
source = ['/Users/Love/Desktop/22.doc']
#备份到这个目标文件下,'/'有无是有差别的
target_dir ='/Users/Love/Documents/'
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
zip_command = "zip -qr '%s' %s" % (target,''.join(source))
if os.system(zip_command) == 0:
    print("success",target)
else:
    print("backup failed")
代码简单,编译器用的是PyCharm,python版本为2.7

猜你喜欢

转载自blog.csdn.net/whjay520/article/details/54090182