Google Colab zip and unzip file

0

If you need sample data test, please download file this link dog-cat-dataset

see download method more Google Colab Download file

google colab file

Upzip file

Upzip file by Linux Command

!unzip is linux command

/content/download.zip is source file

d /content/New_Folder/1 is directory path (please create before unzip)

!unzip /content/download.zip -d /content/New_Folder/1

Archive: /content/download.zip
creating: /content/New_Folder/1/dataset/
inflating: /content/New_Folder/1/dataset/cat-1.jpg
inflating: /content/New_Folder/1/dataset/cat-2.jpg
inflating: /content/New_Folder/1/dataset/cat-3.jpg
inflating: /content/New_Folder/1/dataset/cat-4.jpg
inflating: /content/New_Folder/1/dataset/cat-5.jpg
inflating: /content/New_Folder/1/dataset/dog-1.jpg
inflating: /content/New_Folder/1/dataset/dog-2.jpg
inflating: /content/New_Folder/1/dataset/dog-3.jpg
inflating: /content/New_Folder/1/dataset/dog-4.jpg
inflating: /content/New_Folder/1/dataset/dog-5.jpg
inflating: /content/New_Folder/1/File1.TXT
inflating: /content/New_Folder/1/image.jpg

Upzip file by Shutil Library (I prefer)

Import without installation (colab package included)

import shutil
zipfile = '/content/New_Folder/download2.zip'
unzip_to = '/content/New_Folder/2/'
shutil.unpack_archive(zipfile, unzip_to)

Zip file

zip folder by Linux Command

!zip is linux command

download5.zip is zip file names

/content/New_Folder/1 is directory which will zip

!zip download5.zip /content/New_Folder/1

adding: content/New_Folder/1/ (stored 0%)

Zip file by Linux Command

!zip is linux command

download5.zip is zip file names

/content/New_Folder/1/File1.TXT is file which will zip

/content/New_Folder/1/image.jpg is file which will zip

/content/New_Folder/1/dataset is file which will zip

!zip download6.zip /content/New_Folder/1/File1.TXT /content/New_Folder/1/image.jpg /content/New_Folder/1/dataset

adding: content/New_Folder/1/File1.TXT (stored 0%)
adding: content/New_Folder/1/image.jpg (stored 0%)
adding: content/New_Folder/1/dataset/ (stored 0%)

Zip file by Shutil Library (I prefer)

Import without installation (colab package included)

import shutil
file_to = '/content/New_Folder/download7'
file_format = 'zip'
file_from = '/content/New_Folder/1'
shutil.make_archive(file_to, file_format, file_from)