Abhik Sarkar
Abhik Sarkar

Reputation: 965

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.

Upvotes: 6

Views: 12041

Answers (4)

shivesh kumar
shivesh kumar

Reputation: 85

I am very late to answer this but this is simplest answer ...

Step 1.

Mount google drive with colab

Step 2. Create an output folder in Google drive

Step 3. Drag and drop your folder into the output folder of google drive.

It will be stored in your drive

Upvotes: 1

Parvez
Parvez

Reputation: 86

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

Upvotes: 5

Jaber
Jaber

Reputation: 9

You can pretty much use Linux commands for moving and copying files in colab as well. Just use a ! before that command and run the cell as you usually do. For example:

!mv some_folder another_folder/

should work. Also you need to mount google drive first in your colab notebook.

Upvotes: 1

raul quijada ferrero
raul quijada ferrero

Reputation: 161

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.

Upvotes: 2

Related Questions