• 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'



  • 相关阅读:
    spring使用JdbcDaoSupport中封装的JdbcTemplate进行query
    javascript正则表达式
    Hi java新特性
    jdk 1.5
    jdk 1.6 & 1.7新特性
    core java 10~12(多线程 & I/O & Network网络编程)
    core java 8~9(GUI & AWT事件处理机制)
    core java 7 exception
    core java 5~6(OOP & 高级语言特征)
    响应式布局样例
  • 原文地址:https://www.cnblogs.com/forstudy/p/2403899.html
Copyright © 2020-2023  润新知