From 863c23f42f60009c0de827d007bff120980cf3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Mon, 2 Jan 2023 09:20:24 -0300 Subject: [PATCH] ZIP - Compactando / Descompactando arquivos com zipfile.ZipFile --- .DS_Store | Bin 0 -> 6148 bytes aula186.py | 16 ++++++++++++++++ aula186_compactado.zip | Bin 0 -> 1132 bytes aula186_descompactado/arquivo_0.txt | 1 + aula186_descompactado/arquivo_1.txt | 1 + aula186_descompactado/arquivo_2.txt | 1 + aula186_descompactado/arquivo_3.txt | 1 + aula186_descompactado/arquivo_4.txt | 1 + aula186_descompactado/arquivo_5.txt | 1 + aula186_descompactado/arquivo_6.txt | 1 + aula186_descompactado/arquivo_7.txt | 1 + aula186_descompactado/arquivo_8.txt | 1 + aula186_descompactado/arquivo_9.txt | 1 + aula_186_diretorio_zip/arquivo_0.txt | 1 + aula_186_diretorio_zip/arquivo_1.txt | 1 + aula_186_diretorio_zip/arquivo_2.txt | 1 + aula_186_diretorio_zip/arquivo_3.txt | 1 + aula_186_diretorio_zip/arquivo_4.txt | 1 + aula_186_diretorio_zip/arquivo_5.txt | 1 + aula_186_diretorio_zip/arquivo_6.txt | 1 + aula_186_diretorio_zip/arquivo_7.txt | 1 + aula_186_diretorio_zip/arquivo_8.txt | 1 + aula_186_diretorio_zip/arquivo_9.txt | 1 + 23 files changed, 36 insertions(+) create mode 100644 .DS_Store create mode 100644 aula186_compactado.zip create mode 100644 aula186_descompactado/arquivo_0.txt create mode 100644 aula186_descompactado/arquivo_1.txt create mode 100644 aula186_descompactado/arquivo_2.txt create mode 100644 aula186_descompactado/arquivo_3.txt create mode 100644 aula186_descompactado/arquivo_4.txt create mode 100644 aula186_descompactado/arquivo_5.txt create mode 100644 aula186_descompactado/arquivo_6.txt create mode 100644 aula186_descompactado/arquivo_7.txt create mode 100644 aula186_descompactado/arquivo_8.txt create mode 100644 aula186_descompactado/arquivo_9.txt create mode 100644 aula_186_diretorio_zip/arquivo_0.txt create mode 100644 aula_186_diretorio_zip/arquivo_1.txt create mode 100644 aula_186_diretorio_zip/arquivo_2.txt create mode 100644 aula_186_diretorio_zip/arquivo_3.txt create mode 100644 aula_186_diretorio_zip/arquivo_4.txt create mode 100644 aula_186_diretorio_zip/arquivo_5.txt create mode 100644 aula_186_diretorio_zip/arquivo_6.txt create mode 100644 aula_186_diretorio_zip/arquivo_7.txt create mode 100644 aula_186_diretorio_zip/arquivo_8.txt create mode 100644 aula_186_diretorio_zip/arquivo_9.txt diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7c1c94c06c0d9190f7b070b82cfa959caf0db3ad GIT binary patch literal 6148 zcmeHKJ8Hu~5S>X}7~H6IxmU;y7UP`22e3_K(g+CxNv$g9^3nX}gNcw*q;M17h?%!L znzur)&}c+Ncc1NxNFyR^xS@Pon48@<+(6u4nc90UE+f#4$m zaD}uR);>!BizR?HaSTKTra=V;RddA9pd(+ht|pFwK^M*8L-Wa+6N>uNaenb~(Hh7| z1*pJOf#=vZ*8gAOzs&zr5_eR93j8YtbhSV1cX*}jt+SW2UR&TNxYb`A~!P_y= i+c7rQj<;SEb;Z`WUlYebrz7ulAb$o-7aA3Kv;sH73>Ccq literal 0 HcmV?d00001 diff --git a/aula186.py b/aula186.py index 9a0d222..2180b0e 100644 --- a/aula186.py +++ b/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) diff --git a/aula186_compactado.zip b/aula186_compactado.zip new file mode 100644 index 0000000000000000000000000000000000000000..9f8e3611879f12a7b3094d9f307b20b9fcaec340 GIT binary patch literal 1132 zcmZ|NJxc>Y5XSM%i$MjuU@KTy2uhN>B$vk4mxFkP*ovKkAWD2`gO#12l_;c$h_$7D z2ZIQ97JdRdu~BzN$jm&9y9~F-@!R6~XKA5Wc44ipOs_xutlo|JbC?M~oBMkQ+lRXw zt@+MzXZVsSGxxOgW|>5qM4Q?7kCtT`(loSreEw`(rYTKRo3s0`o@MIN)U_#{e7{;I zmL}F_YVmwvnTj+OZBCCaZY@)lrmD@&?H!W~F4h(G9DzZ(lmc_76um~IJ5l_14Dm|h7=u^`1tm<|M`W{_emOp7`GO_UB& xY=&tfC>4Yh(_y+JD20R+3u4+6lzKvnAu)Xsl(Ndwky7|P?sq%y+^8StegOj4?$rPQ literal 0 HcmV?d00001 diff --git a/aula186_descompactado/arquivo_0.txt b/aula186_descompactado/arquivo_0.txt new file mode 100644 index 0000000..e7377f5 --- /dev/null +++ b/aula186_descompactado/arquivo_0.txt @@ -0,0 +1 @@ +arquivo_0 \ No newline at end of file diff --git a/aula186_descompactado/arquivo_1.txt b/aula186_descompactado/arquivo_1.txt new file mode 100644 index 0000000..9741e29 --- /dev/null +++ b/aula186_descompactado/arquivo_1.txt @@ -0,0 +1 @@ +arquivo_1 \ No newline at end of file diff --git a/aula186_descompactado/arquivo_2.txt b/aula186_descompactado/arquivo_2.txt new file mode 100644 index 0000000..db8d396 --- /dev/null +++ b/aula186_descompactado/arquivo_2.txt @@ -0,0 +1 @@ +arquivo_2 \ No newline at end of file diff --git a/aula186_descompactado/arquivo_3.txt b/aula186_descompactado/arquivo_3.txt new file mode 100644 index 0000000..413cd2e --- /dev/null +++ b/aula186_descompactado/arquivo_3.txt @@ -0,0 +1 @@ +arquivo_3 \ No newline at end of file diff --git a/aula186_descompactado/arquivo_4.txt b/aula186_descompactado/arquivo_4.txt new file mode 100644 index 0000000..ed70dc0 --- /dev/null +++ b/aula186_descompactado/arquivo_4.txt @@ -0,0 +1 @@ +arquivo_4 \ No newline at end of file diff --git a/aula186_descompactado/arquivo_5.txt b/aula186_descompactado/arquivo_5.txt new file mode 100644 index 0000000..380c50d --- /dev/null +++ b/aula186_descompactado/arquivo_5.txt @@ -0,0 +1 @@ +arquivo_5 \ No newline at end of file diff --git a/aula186_descompactado/arquivo_6.txt b/aula186_descompactado/arquivo_6.txt new file mode 100644 index 0000000..d3437a6 --- /dev/null +++ b/aula186_descompactado/arquivo_6.txt @@ -0,0 +1 @@ +arquivo_6 \ No newline at end of file diff --git a/aula186_descompactado/arquivo_7.txt b/aula186_descompactado/arquivo_7.txt new file mode 100644 index 0000000..1101b85 --- /dev/null +++ b/aula186_descompactado/arquivo_7.txt @@ -0,0 +1 @@ +arquivo_7 \ No newline at end of file diff --git a/aula186_descompactado/arquivo_8.txt b/aula186_descompactado/arquivo_8.txt new file mode 100644 index 0000000..449ab27 --- /dev/null +++ b/aula186_descompactado/arquivo_8.txt @@ -0,0 +1 @@ +arquivo_8 \ No newline at end of file diff --git a/aula186_descompactado/arquivo_9.txt b/aula186_descompactado/arquivo_9.txt new file mode 100644 index 0000000..4ef1d0f --- /dev/null +++ b/aula186_descompactado/arquivo_9.txt @@ -0,0 +1 @@ +arquivo_9 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_0.txt b/aula_186_diretorio_zip/arquivo_0.txt new file mode 100644 index 0000000..e7377f5 --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_0.txt @@ -0,0 +1 @@ +arquivo_0 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_1.txt b/aula_186_diretorio_zip/arquivo_1.txt new file mode 100644 index 0000000..9741e29 --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_1.txt @@ -0,0 +1 @@ +arquivo_1 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_2.txt b/aula_186_diretorio_zip/arquivo_2.txt new file mode 100644 index 0000000..db8d396 --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_2.txt @@ -0,0 +1 @@ +arquivo_2 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_3.txt b/aula_186_diretorio_zip/arquivo_3.txt new file mode 100644 index 0000000..413cd2e --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_3.txt @@ -0,0 +1 @@ +arquivo_3 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_4.txt b/aula_186_diretorio_zip/arquivo_4.txt new file mode 100644 index 0000000..ed70dc0 --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_4.txt @@ -0,0 +1 @@ +arquivo_4 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_5.txt b/aula_186_diretorio_zip/arquivo_5.txt new file mode 100644 index 0000000..380c50d --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_5.txt @@ -0,0 +1 @@ +arquivo_5 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_6.txt b/aula_186_diretorio_zip/arquivo_6.txt new file mode 100644 index 0000000..d3437a6 --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_6.txt @@ -0,0 +1 @@ +arquivo_6 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_7.txt b/aula_186_diretorio_zip/arquivo_7.txt new file mode 100644 index 0000000..1101b85 --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_7.txt @@ -0,0 +1 @@ +arquivo_7 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_8.txt b/aula_186_diretorio_zip/arquivo_8.txt new file mode 100644 index 0000000..449ab27 --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_8.txt @@ -0,0 +1 @@ +arquivo_8 \ No newline at end of file diff --git a/aula_186_diretorio_zip/arquivo_9.txt b/aula_186_diretorio_zip/arquivo_9.txt new file mode 100644 index 0000000..4ef1d0f --- /dev/null +++ b/aula_186_diretorio_zip/arquivo_9.txt @@ -0,0 +1 @@ +arquivo_9 \ No newline at end of file