zoukankan      html  css  js  c++  java
  • Python学习3

    一个归档的小程序。

     1 # Filename: backup_ver3
    2 import os
    3 import time
    4 #import sys
    5 #reload(sys)
    6 #sys.setdefaultencoding('utf8')
    7 # 1. The files and directories to be backed up are specified in a list.
    8 source = ['C:\\networkx.txt', 'c:\\backup\\']
    9
    10 # 2. The backip must be stored in a main backup directory
    11 target_dir = 'C:\\backup\\'
    12
    13 # 3. The files are backed up into a zip file.
    14
    15 # 4. The current day is the name of the subdirectory in the main directory
    16 today = target_dir + time.strftime('%Y%m%d')
    17 # The current time is the name of the zip archive
    18 now = time.strftime('%H%M%S')
    19 # create the subbdirectory if it isnt already there
    20 if not os.path.exists(today):
    21 os.mkdir(today)
    22 print 'Successfully created directory', today
    23 # Take a comment from the user to create the name of the zip file
    24 comment = raw_input('Enter a comment-->')
    25 if len(comment) == 0:
    26 target = today + os.sep + now + '.zip'
    27 else:
    28 target = today + os.sep + now + '_' + comment.replace(' ', '_') + '.zip'
    29 # 5. We use the zip command
    30 zip_command = "zip %s %s" %(target, ' '.join(source))
    31
    32 # Run the backup
    33 if os.system(zip_command) == 0:
    34 print 'Successful backup to', target
    35 else:
    36 print 'Backup FAILED'



  • 相关阅读:
    浅谈Linux文件操作
    数据结构学习--队列
    CODE[VS] 1099 字串变换
    CODE[VS] 1026 逃跑的拉尔夫
    CODE[VS] 3027 线段覆盖 2
    LeetCode8.字符串转换整数(atoi) JavaScript
    JS实现继承 JavaScript
    LeetCode7.整数反转 JavaScript
    LeetCode6.Z字形变换 JavaScript
    LeetCode5.最长回文子串 JavaScript
  • 原文地址:https://www.cnblogs.com/forstudy/p/2403899.html
Copyright © 2011-2022 走看看