Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the Google Drive ID of the current Google Colab notebook programmatically?

I am working in a Google Colab notebook. I would like to get this notebook's Google Drive details - like a Python __file__ equivalent - so I can get its folder.

Is there a way that I can get the current notebook's Google Drive ID (and other metadata) programmatically so I can get its parent?

like image 808
Matt Norris Avatar asked Jan 19 '26 19:01

Matt Norris


1 Answers

hi I'm using drive to interact with drive at low level, you can install it in colab easily:

!wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
!tar -C /usr/local -xzf go1.14.2.linux-amd64.tar.gz
import os
os.environ['PATH'] += ":/usr/local/go/bin"
!go get -u github.com/odeke-em/drive/cmd/drive
os.environ['PATH'] += ":/root/go/bin"

and than you can manipulate your drive:

!drive init
!drive index -no-prompt -quiet
!drive pull -directories -depth 4 -quiet -no-prompt -fix-clashes

it works both with file id and names and cover most usecase with drive.

it have an issue with the printing so add the options -quiet -no-prompt to most of the commands.

like image 166
simone viozzi Avatar answered Jan 21 '26 12:01

simone viozzi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!