python自動(dòng)zip壓縮目錄的方法
本文實(shí)例講述了python自動(dòng)zip壓縮目錄的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
這段代碼來壓縮數(shù)據(jù)庫(kù)備份文件,沒有使用python內(nèi)置的zip模塊,而是使用了zip.exe文件
# Hello, this script is written in Python - http://www.python.org
#
# autozip.py 1.0p
#
# This script will scan a directory (and its subdirectories)
# and automatically zip files (according to their extensions).
#
# This script does not use Python internal ZIP routines.
# InfoZip's ZIP.EXE must be present in the path (InfoZip Dos version 2.3).
# (zip23x.zip at http://www.info-zip.org/pub/infozip/)
#
# Each file will be zipped under the same name (with the .zip extension)
# eg. toto.bak will be zipped to toto.zip
#
# This script is public domain. Feel free to reuse it.
# The author is:
# Sebastien SAUVAGE
# <sebsauvage at sebsauvage dot net>
# http://sebsauvage.net
#
# More quick & dirty scripts are available at http://sebsauvage.net/python/
#
# Directory to scan is hardcoded at the end of the script.
# Extensions to ZIP are hardcoded below:
ext_list = ['.bak','.trn']
import os.path, string
def autozip( directory ):
os.path.walk(directory,walk_callback,'')
def walk_callback(args,directory,files):
print 'Scanning',directory
for fileName in files:
if os.path.isfile(os.path.join(directory,fileName)) and string.lower(os.path.splitext(fileName)[1]) in ext_list:
zipMyFile ( os.path.join(directory,fileName) )
def zipMyFile ( fileName ):
os.chdir( os.path.dirname(fileName) )
zipFilename = os.path.splitext(os.path.basename(fileName))[0]+".zip"
print ' Zipping to '+ zipFilename
os.system('zip -mj9 "'+zipFilename+'" "'+fileName+'"')
autozip( r'C:\mydirectory' )
print "All done."
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
- python zip文件 壓縮
- Python壓縮和解壓縮zip文件
- Python壓縮解壓縮zip文件及破解zip文件密碼的方法
- Python中使用gzip模塊壓縮文件的簡(jiǎn)單教程
- python壓縮文件夾內(nèi)所有文件為zip文件的方法
- Python實(shí)現(xiàn)壓縮與解壓gzip大文件的方法
- 使用Python壓縮和解壓縮zip文件的教程
- Python實(shí)現(xiàn)壓縮和解壓縮ZIP文件的方法分析
- python如何壓縮新文件到已有ZIP文件
- python下解壓縮zip文件并刪除文件的實(shí)例
- Python讀寫zip壓縮文件的方法
- Python實(shí)現(xiàn)壓縮文件夾與解壓縮zip文件的方法
相關(guān)文章
將Jupyter?Notebook(.ipynb)文件轉(zhuǎn)換為Python(.py)文件的3種方法
大多數(shù)數(shù)據(jù)科學(xué)在線課程都把Jupyter Notebook作為教學(xué)媒介,這是因?yàn)槌鯇W(xué)者在Jupyter Notebook的單元格中編寫代碼,比編寫包含類和函數(shù)的腳本更容易,這篇文章主要給大家介紹了關(guān)于將Jupyter?Notebook(.ipynb)文件轉(zhuǎn)換為Python(.py)文件的3種方法,需要的朋友可以參考下2023-10-10
python繪制風(fēng)場(chǎng)方向和大小quiver問題
這篇文章主要介紹了python繪制風(fēng)場(chǎng)方向和大小quiver問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08
face++與python實(shí)現(xiàn)人臉識(shí)別簽到(考勤)功能
這篇文章主要為大家詳細(xì)介紹了face++與python實(shí)現(xiàn)人臉識(shí)別簽到(考勤)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08
python針對(duì)Oracle常見查詢操作實(shí)例分析
這篇文章主要介紹了python針對(duì)Oracle常見查詢操作,結(jié)合實(shí)例形式分析了python針對(duì)Oracle常見的子查詢、多表查詢等相關(guān)原理、操作技巧與使用注意事項(xiàng),需要的朋友可以參考下2020-04-04
Python圖像處理之圖像算術(shù)與邏輯運(yùn)算詳解
這篇文章將詳細(xì)講解圖像算法運(yùn)算與邏輯運(yùn)算,包括圖像加法、圖像減法、圖像與運(yùn)算、圖像或運(yùn)算、圖像非運(yùn)算與圖像異或運(yùn)算。感興趣的可以了解一下2022-01-01
python實(shí)現(xiàn)的二叉樹算法和kmp算法實(shí)例
最近重溫?cái)?shù)據(jù)結(jié)構(gòu),又用python,所以就用python重新寫了數(shù)據(jù)結(jié)構(gòu)的一些東西,以下是二叉樹的python寫法2014-04-04
python 實(shí)現(xiàn)圍棋游戲(純tkinter gui)
這篇文章主要介紹了python 如何實(shí)現(xiàn)圍棋游戲,幫助大家利用tkinter制作圖形界面程序,感興趣的朋友可以了解下2020-11-11

