Google-drive – How to get Get a Google Drive Folder List hierarchical structure

google apigoogle-drive

So the question was asked of me if we can get the full hierarchical structure of a specific Google Drive folder so that it was a lot easier to find the location of certain folders. It has also transpired that this will prove valuable to our Knowledge Information Management Team when it comes to dealing with FOI requests, archiving and should we have to migrate any of the data.

My initial searches returned a Google Apps script that would find all child folders and write these to a spreadsheet but when it hit around 800 children it timed out. I reworked the code to maximise efficiency but it still timed out at about 1200. I found another Google Apps script Web App that I can only think used the same code and this too timed out. So Google Apps scripting wasn't the answer.

I have seen people express the lack of understanding for this need as Folders in Google Drive are really Labels and 1 file could reside in multiple folders etc…. Regardless the gauntlet had been thrown down

How do I get a a full hierarchical structure folder list from a Google Drive folder regardless of it's size.

Best Answer

After spending some time searching and working with the apps script solutions and failing I moved to Google Drive APIs and started writing a python script to do what I needed.

The first iteration wrote the output to the screen with each child folder indented below it's parent.

The second iteration took this output and wrote it to a HTML file The third and final iteration wrote the full sorted folder structure with collapsible folders and hyper links to the drive folder and opened this file. I have posted my solution in GitHub for all to benefit from and am happy to take any suggestions on making the code better.