회원 로그인
|
zipfile 모듈
zipfile 모듈
zip파일로 압축 하기, 압축 풀기와 파일 정보를 확인해본다.
예제 내용은 D드라이브에 있는 모든 JPG 파일을 압축한다. 압축한 파일 안의 정보를 확인하고 zipJPG 폴더에 압축을 푼다. (첨부 파일)
참고>
zip파일로 압축 하기, 압축 풀기와 파일 정보를 확인해본다.
예제 내용은 D드라이브에 있는 모든 JPG 파일을 압축한다. 압축한 파일 안의 정보를 확인하고 zipJPG 폴더에 압축을 푼다. (첨부 파일)
#예제 # -*- coding: cp949 -*- import zipfile import glob, os zipDrive_ = 'd:' zipDir_ = 'zipJPG' zipFileName_ = 'zipJPG.zip' print '-zip 파일 하기---------------------' #압축 하기 zipFile_ = zipfile.ZipFile(zipFileName_, 'w') #압축할 파일 가져오기 for fileList_ in glob.glob('%s/*.jpg'%zipDrive_): print fileList_ zipFile_.write(fileList_, os.path.basename(fileList_), zipfile.ZIP_DEFLATED) zipFile_.close() print '-zip 파일 정보---------------------' #압축 파일 읽기 zipFile_ = zipfile.ZipFile('%s/%s'%(zipDrive_,zipFileName_), 'r') #파일 정보 출력 #파일명, 날짜, 용량, 압축 용량 for info_ in zipFile_.infolist(): print info_.filename, info_.date_time, info_.file_size, info_.compress_size zipFile_.close() print '-zip 파일 풀기---------------------' #압축 풀기 zipFile_ = zipfile.ZipFile('%s/%s'%(zipDrive_,zipFileName_), 'r') #압축 된 파일 출력 fileList_ = zipFile_.namelist() for fl_ in fileList_: print fl_ #zipDir_ 폴더에 압축 풀기 zipFile_.extractall(path='./%s/'%zipDir_) zipFile_.close()
참고>
- zipjpg.py (1KB) (0)
댓글 0개
| 엮인글 0개
285개(10/15페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
>> | [Python] zipfile 모듈 | 푸딩뱃살 | 4654 | 2015.09.15 10:17 |
104 | [PHP] array 배열 / sort 정렬 | 푸딩뱃살 | 3475 | 2015.09.02 21:11 |
103 | [PHP] function 함수 | 푸딩뱃살 | 2392 | 2015.08.14 22:28 |
102 | [PHP] while, do, foreach 반복문 | 푸딩뱃살 | 5019 | 2015.08.14 22:25 |
101 | [PHP] if ~ else 조건문 | 푸딩뱃살 | 2594 | 2015.08.14 22:13 |
100 | [PHP] PHP 기초 (에러,주석,변수,연산자) | 푸딩뱃살 | 3268 | 2015.07.08 00:43 |
99 | [C#] override와 new | 푸딩뱃살 | 3267 | 2015.05.14 01:34 |
98 | [C#] 다형성 | 푸딩뱃살 | 2602 | 2015.05.08 15:42 |
97 | [C#] 인터페이스 상속 | 푸딩뱃살 | 2666 | 2015.05.08 14:35 |
96 | [C#] 인터페이스 (Interface) | 푸딩뱃살 | 2595 | 2015.05.07 23:52 |
95 | [C#] 추상 클래스 | 푸딩뱃살 | 3327 | 2015.05.07 22:45 |
94 | [Python] 랜덤 패스워드 생성 | 푸딩뱃살 | 4313 | 2015.03.24 02:34 |
93 | [PHP] php 5.5.x로 업데이트로 인한 preg_replace() 오류 | 푸딩뱃살 | 2756 | 2015.03.14 02:15 |
92 | [PHP] php 5.5.x로 업데이트로 인한 mysql_connect() 오류 | 푸딩뱃살 | 6128 | 2015.03.14 02:01 |
91 | [PHP] PHP Warning: Cannot modity header information ~ PH | 푸딩뱃살 | 2800 | 2015.03.05 15:41 |
90 | [C#] 참조 전달 ref와 값 전달 out | 푸딩뱃살 | 6893 | 2015.02.26 00:10 |
89 | [VisualStudio] Visual Studio Express 2013 Windows Desktop 설치 | 푸딩뱃살 | 3011 | 2015.02.17 03:12 |
88 | [C#] 구조체 | 푸딩뱃살 | 3660 | 2015.01.07 14:17 |
87 | [C#] 오버라이드 (override) | 푸딩뱃살 | 4283 | 2014.11.21 02:17 |
86 | [C#] 이름의 은폐 new | 푸딩뱃살 | 3451 | 2014.11.21 02:13 |