Python備份檔案到指定目錄下

2021-06-03 05:58:00 字數 743 閱讀 9545

python備份檔案到指定目錄下:

#!/usr/bin/python 

# filename: backup_ver1.py

import os

import time

source =[r'c:\python'] #目標目錄

target_dir = 'd:\\python\\' #指定目錄

target = target_dir + time.strftime('%y%m%d%h%m%s') + '.zip'

print target

zip_command = "zip -qr \"%s\" \"%s\"" % (target, ' '.join(source))

if os.system(zip_command) == 0:

print 'successful backup to', target

else:

print 'backup failed'

注意window的命令和linux的命令是不一樣的

window的是:
zip -qr \"%s\" \"%s\"
linux的是:
zip -qr '%s' %s

python 備份檔案指令碼

usr bin env python filename backup ver1.pyimport os import time source r d python test r d python test1 target dir d python test2 remember to change t...

Python 備份檔案,以及備份大檔案

今天分享乙個很有用的小 就是關於檔案的備份 import os 匯入os模組 ori file name r e python mayday.輸入檔案路徑 if os.path.isfile ori file name 判斷該路徑的是否是檔案 擷取檔名,重組檔名 seek num ori file ...

Python實現備份檔案例項

該例項主要實現讀取乙個任務檔案,根據指定的任務引數自動備份.任務檔案的格式 注意,分號後面注釋是不支援的 task 一項任務開始 dir h project 指定備份的目錄 recusive 1 是否遞迴子目錄 suffix h cpp hpp c user filters vcxproj sln ...