Google Colab: How can I mount a particular folder instead of mounting root folder?

Viewed 17784

I am able to mount Google drive using the code below:

from google.colab import drive
drive.mount('/content/drive')

But the above mounts the Root folder enabling all file access within the drive.

I want a particular folder in Google drive to to be mounted (for example just the dataset folder). How can I achieve that?

2 Answers

It's not possible to mount a subfolder, only top-level Drive. You can mount Drive in some out-of-the-way place and then symlink the folder you want someplace more central, e.g.:

from google.colab import drive
drive.mount('/gdrive')
!ln -s "/gdrive/My Drive/theFolder" "/content/theFolder"

If you have confidential files, you can create a new google login for collab studies, at least until google creates a way to mount the folder and not the entire driver.

Related