Skip to content

Instantly share code, notes, and snippets.

@korakot
Last active August 11, 2022 18:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korakot/9bec3d134a70aa9797e17bc0adeb6663 to your computer and use it in GitHub Desktop.
Save korakot/9bec3d134a70aa9797e17bc0adeb6663 to your computer and use it in GitHub Desktop.
Get file_id of a file on Google Drive from Colab
from subprocess import getoutput
from IPython.display import HTML
!apt install xattr &>log
def show_link(fn):
fid = getoutput("xattr -p 'user.drive.id' '%s'" % fn)
return HTML(f"<a href=https://colab.research.google.com/drive/{fid} target=_blank>notebook</a>")
# using !pip install kora
from kora.xattr import get_id
get_id(fn)
from subprocess import getoutput
from IPython.display import HTML
from google.colab import drive
drive.mount('/content/drive') # access drive
# need to install xattr
!apt-get install xattr > /dev/null
# get the id
fid = getoutput("xattr -p 'user.drive.id' /content/drive/My\\ Drive/Colab\\ Notebooks/R.ipynb")
# make a link and display it
HTML(f"<a href=https://colab.research.google.com/drive/{fid} target=_blank>notebook</a>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment