Home Copy folders to your Google Drive
Post
Cancel

Copy folders to your Google Drive

Sometimes you will be shared documents through Google Drive. If the file or folder is in PDF, MP4, or simple data format, you can view it directly there. You can easily create a copy of the file to have full ownership, but for folders, you can only create a shortcut instead of a copy. That's why I created a very simple script to easily create a copy of a folder.

Problem and solution

Problem

The problem is that I am shared a folder, and I want to create a copy in my own folder. There are some reasons to create a copy on my drive. The first case is if I only store the link or create a shortcut, then if that file is deleted (by Google or the owner), I won't be able to access it. The second case is when the folder is set to public mode, but after a while, the owner will change it to private. In this case, I can only access it when the owner grants permission. And sometimes I download courses to my computer to view gradually. This downloading process takes a lot of time because I have to wait for Google to zip the folder and then split it into multiple parts before the downloading step. This process is time-consuming and consumes computer memory.

Solution

My initial idea was to use Google Colab. Then the user will create a "shortcut of the shared folder" in their Google Drive. At this point, the user will pass the folder name parameter. When running the script, Google Drive will be mounted into Colab. We can then copy the target folder into the user's Google Drive. But the issue with copying is that only the shortcut created by the user is selected for copying. Then I tried to zip the shortcut, and it was possible to extract the contents from the shortcut. However, this approach is not optimized because it involves creating a zip file and then unzipping it.

Then my friend suggested a way to copy the contents of the shortcut using a similar method as mentioned here. So the optimization issue was resolved. Skipping the zip and unzip steps, a folder of 17GB only takes 470 seconds, and for a small file of 125MB, it only takes 0.94 seconds.

But there was another problem where the user had to copy the folder name to paste it into Colab. I found this operation a bit difficult. So instead of copying the name, I replaced it with copying the "link address". From the link address, I extracted the folder name and directly found the path to that folder through the shortcut. Then the script will automatically perform the copy operation as usual.

User Guide

Just follow 3 steps: create a shortcut, get the link of the folder, and paste it into Colab, then run it. Next, we will go through each step in detail.

Step 1: Create a shortcut

I will use this folder as an example.

You click on the folder name and select "add shortcut to my drive".

After the selection window appears, click on the "add shortcut" button.

Step 2: Copy the link

Click on the folder name and select "Get link".

Then click on "Copy".

OR You can copy the link from the search bar.

Step 3: Paste the link into Colab and run it

Access this link Paste your link into the box as shown in the image below

Click on "Runtime" and then "Run all"

Drive will request access permission from Colab. You can choose as shown in the images.

Acess to drive
Choose your account
Allow accessing to your drive

After receiving the "Finished" notification, you can check in your drive in the COPY folder under my drive

Conclusion

Those are the steps to copy a shared folder to your personal drive. With the above steps, you have complete ownership of those documents, and if the original copy is deleted, it will not be affected. The only drawback is that your storage space must be large enough, while the "Free" account is only allocated 15GB. However, with a student account or an "edu" type Google account, you will have unlimited storage, making it easy to store documents.

This post is licensed under CC BY 4.0 by the author.