티스토리 뷰

The ZIP file format is a common archive and compression standard. This module provides tools to create, read, write, append, and list a ZIP file. Any advanced use of this module will require an understanding of the format, as defined in PKZIP Application Note.

This module does not currently handle multi-disk ZIP files. It can handle ZIP files that use the ZIP64 extensions (that is ZIP files that are more than 4 GByte in size). It supports decryption of encrypted files in ZIP archives, but it currently cannot create an encrypted file. Decryption is extremely slow as it is implemented in native Python rather than C.

The module defines the following items:

class zipfile.ZipFile

The class for reading and writing ZIP files. See section ZipFile Objects for constructor details.


ZipFile.close()

Close the archive file. You must call close() before exiting your program or essential records will not be written.


ZipFile.extract(member[path[pwd]])

Extract a member from the archive to the current working directory; member must be its full name or a ZipInfo object). Its file information is extracted as accurately as possible. path specifies a different directory to extract to. member can be a filename or a ZipInfo object. pwd is the password used for encrypted files.

Returns the normalized path created (a directory or new file).

참고 : https://docs.python.org/2/library/zipfile.html


path내의 .zip 확장자 압축파일은 모조리 압축해제를 하는 스크립트입니다.

* 경로명은 'C:\suspect' 를 준 상태입니다.


1. 설명은 소스의 주석으로 대체하겠습니다. 

간단하게 설명하자면, path 내의 zip 확장자를 모조리 찾아서 zip 파일의 절대경로명을 zipfile.Zipfile을 이용하여 zip 파일을 binary로 읽은 후에 패스워드를 풀고 압축을 푸는 과정이 되겠습니다 :)

* 소스가 흐릿하게 보이는데, 클릭 하시면 잘 보입니다!


2. 임의의 txt를 만들고, 압축 후 비밀번호를 걸어보겠습니다.


3. 위에 'suspect'라고 된 알집을 확인 하고, 스크립트를 실행하겠습니다.


4. 경로에 가보면 알아서 풀려있는 것을 확인 가능합니다.


인턴쉽에서 일을 하다가 zip 파일을 다 풀어야 하는 상황이 와서 스크립트를 작성했습니다.

경로명에 C:\ 를 주면 C:\안의 zip 파일은 모두 풀립니다 :)


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함