How to Download Multiple Files or an Entire Folder from Google Colab

How to download folders from Google Colaboratory

Download the folder directly from the files tab that you can find on an arrow on top left of the screen
https://colab.research.google.com/notebooks/io.ipynb

Is there a way to download data from a public link to google colab?

You can use gdown.

For example, an image url

https://drive.google.com/file/d/1ztBz3C_2BlXgNGK2mbarGnVqoI287_XT/view?usp=sharing

It's id = 1ztBz3C_2BlXgNGK2mbarGnVqoI287_XT

So, you can download it with

!gdown --id 1ztBz3C_2BlXgNGK2mbarGnVqoI287_XT

How to download file created in Colaboratory workspace?

Use files colab lib

from google.colab import files
files.download('example.txt')

PS: use chrome browser

How to copy folders with same names recursively to another folder in Google Colab

The solution was to copy the files one by one recursively:

import os, shutil

for i in [x for x in range(10) if ((x != 9) and (x != 1))]:
# print(fileList[i])
# Train
if(i > 2):
subPathList = glob.glob('/content/NewDataset/'+fileList[i]+'/**/', recursive=False)
for subPath in subPathList:
for im in os.listdir(subPath):
imFullPath = os.path.join(subPath, im)
targetPath = os.path.join('/content/train',subPath.split('/')[-2]+ '/')
# print('Train: ', targetPath)
shutil.copy(imFullPath, targetPath)
# Validate
else:
subPathList = glob.glob('/content/NewDataset/'+fileList[i]+'/**/', recursive=False)
for subPath in subPathList:
for im in os.listdir(subPath):
imFullPath = os.path.join(subPath, im)
targetPath = os.path.join('/content/valid',subPath.split('/')[-2] + '/')
# print('Validate: ', targetPath)
shutil.copy(imFullPath, targetPath)


Related Topics



Leave a reply



Submit