欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實現(xiàn)windows下文件備份腳本

 更新時間:2018年05月27日 16:09:10   作者:dazuo01  
這篇文章主要為大家詳細介紹了python實現(xiàn)windows下文件備份的腳本,具有一定的參考價值,感興趣的小伙伴們可以參考一下

在windows下用python腳本實現(xiàn)文件的備份,參考《A Byte of Python3》第十一章(Page59)。

#!/usr/bin/python 
# -*- coding: cp936 -*- 
 
import os 
import time 
 
source = ['E:\\'] # 待備份文件在E盤根目錄下 
running = True 
 
while running: 
  your_source = raw_input("Your own path or your own file path:") 
  #如果使用input(),在運行后輸入路徑名時,需要在兩邊加上" ",下面的input同理 
  #比如欲備份E盤下zipme文件夾里的hello.txt文件,則應輸入zipme\\hello.txt 
  source.append(your_source) 
  if raw_input("Do you want to add file or folder(y/n):")=='n': 
    running = False 
 
target_dir = 'E:\\backup\\' #備份生成的文件存放的路徑 
 
#以當前日期和時間為文件名命名生成的壓縮文件 
target = target_dir+\ 
     time.strftime('%Y')+\ 
     time.strftime('%m')+\ 
     time.strftime('%d')+\ 
     time.strftime('%H')+\ 
     time.strftime('%M')+\ 
     time.strftime('%S')+'.rar' 
 
#使用zip命令壓縮文件 
zip_command = "zip -qr {0} {1}".format(target, ''.join(source)) 
 
#通過給系統(tǒng)傳遞參數(shù)來執(zhí)行壓縮命令(壓縮使用的是WinRAR所帶文件rar.exe來執(zhí)行壓縮) 
if os.system(zip_command) == 0: 
  print('Successful backup to',target) 
else: 
  print('Backup FAILED') 

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論