简体   繁体   中英

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.

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')

输出图像

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

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM