Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving Folder from Google Colab to Google Drive

I am using Google Colab for Machine Learning. Many times I need to download solution CSV using Google Drive using Pydrive. As shown below

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

uploaded = drive.CreateFile({'title': 'dogsVScats.csv'})
uploaded.SetContentFile('dogsVScats.csv')
uploaded.Upload()
print('Uploaded file with ID {}'.format(uploaded.get('id')))

How to replicate this same process fora folder. Not File.

like image 697
Abhik Sarkar Avatar asked Mar 07 '23 05:03

Abhik Sarkar


2 Answers

Use the Same google account for Colab and Gdrive, to avoid error.

open new notebook in colab and execute the below code

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

output image

visit the link and give access permission

then copy the code from the link and paste it in the colab page

from colab, go to gdrive path using below command

% cd drive/My\ Drive/

then use colabs as using terminal with ! symbol before the commands

!mkdir sample

you can view the modifications from side panel on left side

like image 194
Parvez Avatar answered Mar 22 '23 20:03

Parvez


Compress your entire folder and download the compressed file instead. In fact I think it would speed your download. I found that p7zip works flawlessly with Colab.

like image 43
raul quijada ferrero Avatar answered Mar 22 '23 20:03

raul quijada ferrero