I mount my Google Drive in Colab like this:
from google.colab import drive drive.mount('/content/drive') Now when I want to unzip the file "tommuddi.zip" which resides in the folder "drive/MyDrive/"
I have to access it using "drive/MyDrive/tommuddi.zip" which is cumbersome:
from zipfile import ZipFile file_name = 'drive/MyDrive/tommuddi.zip' with ZipFile(file_name, 'r') as zip: zip.extractall() print('Done') Instead, I would like to access is using
file_name = 'tommuddi.zip' How could I make it so that Colab assumes that "MyDrive" is the root so that the above works?
When I try this...
from google.colab import drive drive.mount('/content/drive/MyDrive') ... it throws the error
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-25-c0fc2c3766a0> in <module>() 1 from google.colab import drive ----> 2 drive.mount('/content/drive/MyDrive') 1 frames /usr/local/lib/python3.7/dist-packages/google/colab/drive.py in _mount(mountpoint, force_remount, timeout_ms, use_metadata_server, ephemeral) 285 ': timeout during initial read of root folder; for more info: ' 286 ') --> 287 raise ValueError('mount failed' + extra_reason) 288 elif case == 2: 289 # Not already authorized, so do the authorization dance. ValueError: mount failed Thank you!
1 Answer
Got it: One has to use cd drive to go to that directory:
from google.colab import drive drive.mount('/content/drive') %cd drive/MyDrive After doing that, we are in the MyDrive directoy, and we can access its files directly.
