Last active
April 9, 2016 14:30
-
-
Save niko86/4cc80e702f60475ee3ade91e6b20403d to your computer and use it in GitHub Desktop.
Extracts all .shp files from any .zip files in the current working directory of the script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! python3 | |
import os | |
import shutil | |
import zipfile | |
from zipfile import ZipFile | |
from os.path import basename | |
list_zip_file = [files for files in os.listdir(".") if zipfile.is_zipfile(files)] | |
for zip_file in list_zip_file: | |
zip_file = ZipFile(zip_file) | |
list_shp_files = [member.filename for member in zip_file.infolist() if member.filename.endswith('.shp')] | |
for shp_file in list_shp_files: | |
source = ZipFile.open(zip_file, name=shp_file, mode='r') | |
target = basename(shp_file) | |
shutil.copyfileobj(source, open(target, mode='wb')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://dl.dropboxusercontent.com/u/7705693/opmplc_essh_hx.zip
https://dl.dropboxusercontent.com/u/7705693/opmplc_essh_ov.zip
Some files to play with, if someone wishes to test it.