Python implements a backup program instance in windows

Source: Internet
Author: User
This article describes how to implement a backup program in python in windows. if you need a backup program, you can refer to the Python backups mentioned in many books in linux, in xp, you can also perform the backup function. the code is almost the same, that is, the package is different. Winrar is also used, and the same applies to other compressed files.

First, we need to add the winrar path to the path, which is valid only after the host is restarted.
Note: after you add the winrar path to the path, you must restart it. Otherwise, the path setting will not take effect and the package will fail!

The command used here is: winrar a xxx.zip xxxx
Xxx is any character

The instance code is as follows:

# Backup script used for backup # Filename: backup_ver1.py import OS import time import sys # Source file path sourc = ['G: // test // test.txt '] # target_dir = 'G: // '# Name of the backup file target = target_dir + time.strftime('policyuncm=d?h=m=s'{}'.rar' # zip_command = "zip-qr '% s' % s" % (target ,''. join (sourc) # zip_command = "winrar a/" % s/"% s" % (target ,''. join (sourc) zip_command = "winrar a % s" % (target ,''. join (sourc) print zip_com Mand if OS. system (zip_command) = 0: print 'package successful! '+ Target else: print' packaging failed!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.