How to copy a folder with all the subfolders from colab to drive?

Question:

I need to copy a folder I created in the temporary space of Google Colab to Drive.

This is the command

%cp Thesis2023 /drive/MyDrive/Thesis2023

Thesis 2023 is the folder I need to copy to drive, but I get this error

cp: -r not specified; omitting directory 'Thesis2023'
Asked By: Marco B

||

Answers:

In order to copy all files from the folder to the new folder created in the destination, you need to use the -r command (-r stands for recursive):

cp -r Thesis2023 /drive/MyDrive/Thesis2023

This code should copy the folder and everything inside to the new directory, in this case your Google drive.

I see that the question tag is python: If you are trying to use this command in a Python program, you can import subprocess and use the subprocess.run command to run the cp command:

import subprocess
subprocess.run(['cp', '-r', 'Thesis2023', '/drive/MyDrive/Thesis2023'])
Answered By: user21448598