파일 백업-python 3 폴 더 아래 모든 파일 압축 처리
# !/usr/bin/python3
# coding:utf-8
# Filename: backup_ver1.py
import os,time,zipfile
def createZip(filePath,savePath,note = ''):
'''
zip 。
:param filePath:
:param savePath:
:param note:
:return:
'''
today = time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')
fileList=[]
if not os.path.exists(today):
os.mkdir(today)
print('mkdir successful')
if len(note) == 0:
target = savePath + os.sep + today + os.sep + now + '.zip'
else:
target = savePath + os.sep + today + os.sep + now + '_' + note + '.zip'
newZip = zipfile.ZipFile(target,'w')
for dirpath,dirnames,filenames in os.walk(filePath):
for filename in filenames:
fileList.append(os.path.join(dirpath,filename))
for tar in fileList:
newZip.write(tar,tar[len(filePath):])#tar ,tar[len(filePath)]
newZip.close()
print('backup to',target)
4.567913.함 수 를 정의 한 후에 호출 합 니 다.
def unZip(filePath,unzipPath): ''' zip :param filePath: :param unzipPath: :return: ''' file = zipfile.ZipFile(filePath) file.extractall(unzipPath) print('unzip successfully to',unzipPath)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Python의 None과 NULL의 차이점 상세 정보그래서 대상 = 속성 + 방법 (사실 방법도 하나의 속성, 데이터 속성과 구별되는 호출 가능한 속성 같은 속성과 방법을 가진 대상을 클래스, 즉 Classl로 분류할 수 있다.클래스는 하나의 청사진과 같아서 하나의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.