Skip to content

Instantly share code, notes, and snippets.

@eugen-hoppe
Last active February 3, 2025 14:54
Show Gist options
  • Select an option

  • Save eugen-hoppe/93ece48e0b224b853698249502aa9ba9 to your computer and use it in GitHub Desktop.

Select an option

Save eugen-hoppe/93ece48e0b224b853698249502aa9ba9 to your computer and use it in GitHub Desktop.
Copies a ZIP file from Google Drive to the local VM in Google Colab and unzips it.
import shutil
import zipfile
import os
from google.colab import drive
def copy_and_unzip_from_drive(drive_path, local_path, drive_mount = "/content/drive"):
"""docs: https://gist.github.com/eugen-hoppe/93ece48e0b224b853698249502aa9ba9"""
drive.mount(drive_mount)
os.makedirs(local_path, exist_ok=True)
local_zip_path = "/content/drive_temp.zip"
shutil.copy(drive_path, local_zip_path)
with zipfile.ZipFile(local_zip_path, 'r') as zip_ref:
zip_ref.extractall(local_path)
os.remove(local_zip_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment