ZIP - Compactando / Descompactando arquivos com zipfile.ZipFile
This commit is contained in:
16
aula186.py
16
aula186.py
@@ -29,3 +29,19 @@ def criar_arquivos(qtd: int, zip_dir: Path):
|
||||
|
||||
|
||||
criar_arquivos(10, CAMINHO_ZIP_DIR)
|
||||
|
||||
# Criando um zip e adicionando arquivos
|
||||
with ZipFile(CAMINHO_COMPACTADO, 'w') as zip:
|
||||
for root, dirs, files in os.walk(CAMINHO_ZIP_DIR):
|
||||
for file in files:
|
||||
# print(file)
|
||||
zip.write(os.path.join(root, file), file)
|
||||
|
||||
# Lendo arquivos de um zip
|
||||
with ZipFile(CAMINHO_COMPACTADO, 'r') as zip:
|
||||
for arquivo in zip.namelist():
|
||||
print(arquivo)
|
||||
|
||||
# Extraindo arquivos de um zip
|
||||
with ZipFile(CAMINHO_COMPACTADO, 'r') as zip:
|
||||
zip.extractall(CAMINHO_DESCOMPACTADO)
|
||||
|
||||
BIN
aula186_compactado.zip
Normal file
BIN
aula186_compactado.zip
Normal file
Binary file not shown.
1
aula186_descompactado/arquivo_0.txt
Normal file
1
aula186_descompactado/arquivo_0.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_0
|
||||
1
aula186_descompactado/arquivo_1.txt
Normal file
1
aula186_descompactado/arquivo_1.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_1
|
||||
1
aula186_descompactado/arquivo_2.txt
Normal file
1
aula186_descompactado/arquivo_2.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_2
|
||||
1
aula186_descompactado/arquivo_3.txt
Normal file
1
aula186_descompactado/arquivo_3.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_3
|
||||
1
aula186_descompactado/arquivo_4.txt
Normal file
1
aula186_descompactado/arquivo_4.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_4
|
||||
1
aula186_descompactado/arquivo_5.txt
Normal file
1
aula186_descompactado/arquivo_5.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_5
|
||||
1
aula186_descompactado/arquivo_6.txt
Normal file
1
aula186_descompactado/arquivo_6.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_6
|
||||
1
aula186_descompactado/arquivo_7.txt
Normal file
1
aula186_descompactado/arquivo_7.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_7
|
||||
1
aula186_descompactado/arquivo_8.txt
Normal file
1
aula186_descompactado/arquivo_8.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_8
|
||||
1
aula186_descompactado/arquivo_9.txt
Normal file
1
aula186_descompactado/arquivo_9.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_9
|
||||
1
aula_186_diretorio_zip/arquivo_0.txt
Normal file
1
aula_186_diretorio_zip/arquivo_0.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_0
|
||||
1
aula_186_diretorio_zip/arquivo_1.txt
Normal file
1
aula_186_diretorio_zip/arquivo_1.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_1
|
||||
1
aula_186_diretorio_zip/arquivo_2.txt
Normal file
1
aula_186_diretorio_zip/arquivo_2.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_2
|
||||
1
aula_186_diretorio_zip/arquivo_3.txt
Normal file
1
aula_186_diretorio_zip/arquivo_3.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_3
|
||||
1
aula_186_diretorio_zip/arquivo_4.txt
Normal file
1
aula_186_diretorio_zip/arquivo_4.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_4
|
||||
1
aula_186_diretorio_zip/arquivo_5.txt
Normal file
1
aula_186_diretorio_zip/arquivo_5.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_5
|
||||
1
aula_186_diretorio_zip/arquivo_6.txt
Normal file
1
aula_186_diretorio_zip/arquivo_6.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_6
|
||||
1
aula_186_diretorio_zip/arquivo_7.txt
Normal file
1
aula_186_diretorio_zip/arquivo_7.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_7
|
||||
1
aula_186_diretorio_zip/arquivo_8.txt
Normal file
1
aula_186_diretorio_zip/arquivo_8.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_8
|
||||
1
aula_186_diretorio_zip/arquivo_9.txt
Normal file
1
aula_186_diretorio_zip/arquivo_9.txt
Normal file
@@ -0,0 +1 @@
|
||||
arquivo_9
|
||||
Reference in New Issue
Block a user