Example of using RAR command to compress multiple folders in Windows system python

Source: Internet
Author: User
Copy CodeThe code is as follows:


#!/usr/bin/env python
# Filename:backup_ver1.py

Import OS
Import time

# 1. The files and directories to is backed up is specified in a list.
#source =['/home/swaroop/byte ', '/home/swaroop/bin ']
source=[' d:\\filecopier\\*.* ', ' d:\\jeecms_doc\\*.* ']
# If you're using Windows, use source=[r ' C:\Documents ', R ' D:\Work ') or something like that

# 2. The backup must is stored in a main backup directory
#target_dir = '/mnt/e/backup/' #Remember to the
Target_dir= ' e:\\temp\\ ' #Remember to the change

# 3. The files is backed up into a zip file
# 4. The name of the ZIP archive is the current date and time
Target=target_dir+time.strftime ('%y%m%d%h%m%s ') + '. Zip '

# 5. We Use the Zip command (in unix/linux) to put the files in a zip archive
#zip_command = "Zip-qr '%s '%s"% (target, ". Join (source))
zip_command= "rar a" + target + ". Join (source)
# Run The Backup
If Os.system (Zip_command) ==0:
print ' successful backup to ', target
Else
print ' Backup 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.