Colab is becoming more and more popular. In a previous post, we have explained how to get data from Google Drive into Colab. In this post, we will show you how to download files and folders from Colab.
How to Download Files from Colab
Let’s say, that I want to download the file README.md which is under the sample_data folder.
We can either click on the file and then click Download or we can download it programmatically as follows:
from google.colab import files files.download('/content/sample_data/README.md')
Note, that we can get the file path by clicking on the file and then clicking on Copy path.
How to Download Folders from Colab
We cannot download directly multiple files from Colab. However, we can zip the files under the folder and then download the
.zip file. Assume that we want to download all the files under the sample_data folder. The first thing that we need to do is to create the zip file as follows:
!zip -r /content/sample_data.zip /content/sample_data
The command is
!zip followed by
r which means “recursive”, then we write the file path of the zipped file (i.e.
/content/sample_data.zip) and finally, we write the folder that we want to zip (i.e.
/content/sample_data) and voila, the zip file is generated :-).
Lastly, we can download the zip file as before: