5
votes

I studied some ways of loading data to Colaboratory from the official notebook.

But it only connects the colab with Google Drive's "My Drive" folder by the command

drive.mount('/content/gdrive')

Picture for colab directory tree

However, I would like to access Google Drive's "Computers" folder in Colab. Is there some way to do it?

Picture for Google Drive web directory tree

Thanks!

5
Is it not available in /content/gdrive/My\ Drive/Computers? Or, do you mean that you want to access other files from your local computer?Bob Smith
@BobSmith thanks for answering. Unfortunately, that's not the case. The "Computer" directory, according to my understanding is a sync directory from your (local) computer (if you are using google drive desktop, it could be any folder, and doesn't have to be under "Google Drive"). And it is placed as a parallel folder on Google Drive web. But when I mount "/content/gdrive", there is only one subfolder, which is "My Drive". And "My Drive" folder certainly doesn't include the "Computer" directory, but only includes my files under "Google Drive". I'll try editing the question to make it clear.jfang

5 Answers

0
votes

Here is a partial solution that may work for you:

By using the Files: update API call, you can add "root" as a parent to any folder inside the computer that you're syncing (set addParents="root"). This way a folder can live in both your Computers section and your My Drive, and should show up in Colaboratory.

7
votes

From Computers just right click the file and then click Add Shortcut to Drive to the file you would like to open in Colab. This will create a shortcut of that file to Drive. Now when you modify the file there(gdrive) it will automatically be updated on Computers as well. See image below.

Drive instructions

3
votes

Here is a hack that worked for me. You will need two Google accounts: let's call the one with which you're currently mounting to "Computers" from your local drive A, and the one in which you want to run the notebook B.

  1. Using account A, ensure that your files are correctly mounted and visible under "Computers" in your Drive's directory structure.

  2. Turn on link sharing for this directory.

  3. Basically, you now need to share this link with yourself. Log into account B and visit the link; doing so should land you in the "Shared with me" area of Drive, where you should see your directory.

  4. Drag and drop the directory onto the "My Drive" area in the filetree on the left. This will add the shared directory to the Drive of account B (i.e. no longer in a "Computers" directory, but now in a "My Drive" directory).

  5. In Colab using account B, mount your Drive as usual. You should now be able to access your files under "My Drive" of account B, shared with yourself via account A.

From what I can tell, sharing the directory is the only workaround that can actually move the whole directory from a "Computers" area to a "My Drive" one.

3
votes

I found a way works for me, the basic principle is to change the way you sync files.

From your expressions, I think your aim is to apply synced files from your local computer to Google Colaboratory. Though we can't mount 'Computers' to Colaboratory, we can mount 'My Drive'.

What I do is as follows:

  1. Create a folder in 'My Drive', for example as 'Gd test drive'.

  2. Sync 'Gd test drive' folder to local computer, shown as following figure: List item

    P.S. This figure refers to How Does Google Backup and Sync Work: A Comprehensive Guide for demonstration.

  3. Create files you want to sync with Google Drive, and they will be synced and accessed by Google Colaboratory.

  4. Mount your drive to Colaboratory, then you can get access to your target folders or files.

    from google.colab import drive
    drive.mount('/gdrive')
    
1
votes

In the web app of Google Drive, drag the folders of desire to your main drive. Requires you to remount drive in your colab notebook.