The Quickest Way to Extract Folder Structure from Google-Drive

Guy Barner
2 min readApr 1, 2021

--

Impossible structure

tl;dr: this is a quick tip on how to get your folder structure from Google Drive without giving permission to any 3rd parties. The whole thing shouldn’t take more than 5 minutes.

The Google Drive folder structure can become very complex, very quickly, making it impossible to manually extract your folder structure.

First — why would you want to do that? Well, there are a few reasons:

  • for training new employees
  • for re-organizing your existing content
  • for migrating your content to a new drive

There are many 3rd party solutions and Google Sheets add-ons that will let you do that quickly. The issue is, you usually don’t want to give some unknown 3rd party access to your files for a one-off need.

To the rescue — Google Colab. Colab is an online tool for executing code in the cloud. Wait, wait! No need to run screaming — we’ll only copy-paste about 10 lines of text.

A few easy steps:

  1. Go to Google Colab.

2. Press New > New Notebook

3. In the first line of code, write:

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

4. Activate the code by clicking “play”, press the link, and log into the account from which you’d like to extract the folder structure. Copy the password given after signup, and paste it in the input box back in Colab.

5. Create a new “code snippet” by clicking on the “+ Code” button, and paste the following:

import osstartpath = "/gdrive"def list_files(startpath):   for root, dirs, files in os.walk(startpath):      level = root.replace(startpath, '').count(os.sep)      indent = ' \t' * (level)      print('{}{}'.format(indent, os.path.basename(root)))      subindent = '\t' * (level + 1)      #for f in files:         #print('{}{}'.format(subindent, f))list_files(startpath)

if you’d like the names of the files as well, remove the two ‘#’ at the end of the snippet.

6. Click “play”. Whoa, look at that!

7. Copy the result, and in Google Sheets, right-click the A1 cell, hit paste special > Paste values only.

Congrats! Now go organize your files.

This is the first in the Tagbox ‘Quick Tip’ series. Our goal at Tagbox is to help people and organizations organize their content in any way you can, whether with our content management platform, or by offering some quick advice.

Any questions? Feel free to email me directly at guy@tagbox.io.

--

--

Guy Barner

A Product Manager with time to spare. Working on a super cool new project, visit us at tagbox.io