2016-08-01 3 views
0

zip에 저장된 파일의 경로를 무시하고 싶습니다. 내가파이썬에서 zip 파일을 추출 할 때 경로를 무시하는 방법

/mygoodpath을 선호

/mygoodpath/ignorepath/filename.txt :

ZipFile.extract('/ignorepath/filename.txt', '/mygoodpath') 

이는 followng을 생성합니다 : 나는 다음을 사용 /filename.txt

나는 나중에 약간의 엣지 경우를 가지지 만, 여는 ZipFile.open뿐만 아니라 shutil.move를보고있다. 이것을 처리하는 가장 좋은 방법은? 바이너리 파일도이있는 경우

+0

'ZipExtFile'를 사용해보십시오, 단지 B 옵션을 추가, – Jacob

답변

0

물론 ... 버퍼 인터페이스를 지원하지 않습니다 Zipfile.open

with ZipFile('spam.zip') as myzip: 
    with myzip.open('/ignorepath/filename.txt') as infile: 
     with open('/mygoodpath/filename.txt', 'w') as outfile: 
      outfile.write(infile.read()) 
+0

전문 – Jacob

관련 문제