Last active
February 3, 2025 14:54
-
-
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.
This file contains hidden or 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
| 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