---
title: "Organise Google Drive files into a JavaScript object for use with Google Apps Script"
author: "Phil Bainbridge"
date: 2023-01-19T20:17:37+00:00
canonical_url: https://pulse.appsscript.info/p/2023/01/organise-google-drive-files-into-a-javascript-object-for-use-with-google-apps-script/
markdown_url: https://pulse.appsscript.info/p/2023/01/organise-google-drive-files-into-a-javascript-object-for-use-with-google-apps-script.md
categories:
  - "Beginner"
  - "Drive"
  - "Snippet"
tags:
  - "pbainbridge.co.uk"
featured_image: https://pulse.appsscript.info/files/2023/01/Filestoloopthroughandorganise.png
description: "Another useful tip from Phil Bainbridge: \"The following Google Apps Script is designed to go through a folder of Google Drive files where a number of tutors have individual files for groups of students they teach. The code will collate all of the relevant files (specifically their IDs) that belong to each tutor, so that at a later date we can loop through the organised data set and create individual Google Sheets for each tutor and compile their student data into it.\""
---

# Organise Google Drive files into a JavaScript object for use with Google Apps Script

![Organise Google Drive files into a JavaScript object for use with Google Apps Script](https://pulse.appsscript.info/files/2023/01/Filestoloopthroughandorganise.png)

> Organise Google Drive files into a JavaScript Object so that they can be looped through for each named individual.
> [https://www.pbainbridge.co.uk/2023/01/organise-files-into-javascript-object.html](https://www.pbainbridge.co.uk/2023/01/organise-files-into-javascript-object.html)Files to loop through and organise

The following Google Apps Script is designed to go through a folder of Google Drive files where a number of tutors have individual files for groups of students they teach. The code will collate all of the relevant files (specifically their IDs) that belong to each tutor, so that at a later date we can loop through the organised data set and create individual Google Sheets for each tutor and compile their student data into it.

What this code ultimately allows us to achieve is the ability to go through the files and get them organised for further coding.

In this example we have a file name pattern of **ModuleCode – Tutor Name – Group Number** for example **ABC – Jane Doe – Grp 02**. So we want to collate all of the files that belong to Jane Doe first, then move on to the next tutor (*Micky Mouse* in this example).

The collated data will look like this:

```
{
 "Jane Doe":[
 "FILE ID HERE",
 "FILE ID HERE",
 "FILE ID HERE"
 ],
 "Micky Mouse":[
 "FILE ID HERE",
 "FILE ID HERE"
 ]
}
```

Source: *[The Gift of Script: Organise files into a JavaScript Object*](https://www.pbainbridge.co.uk/2023/01/organise-files-into-javascript-object.html)

---

*Published by [Phil Bainbridge](https://pulse.appsscript.info/p/author/phillipbainbridge/) on [Pulse](https://pulse.appsscript.info/). Original article: [https://pulse.appsscript.info/p/2023/01/organise-google-drive-files-into-a-javascript-object-for-use-with-google-apps-script/](https://pulse.appsscript.info/p/2023/01/organise-google-drive-files-into-a-javascript-object-for-use-with-google-apps-script/)*
