Tuesday 31 January 2023

Organise files into a JavaScript Object 2.0

The following Google Apps Script is an enhanced version of this blog post for organising files into a JavaScript Object. The difference this time however is that we are extracting 3 (not 1) pieces of information from the CSV file name and coding them into an iteratble JavaScript Object. This is more likely the process you will want to use going forwards given the extra flexibility.

The code 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 (their IDs, the module code and group number) 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:

{Micky Mouse=[{fileId=FILE ID HERE, group=Grp 05.csv, moduleCode=CDE}, {moduleCode=CDE, fileId=FILE ID HERE, group=Grp 01.csv}], Jane Doe=[{group=Grp 04.csv, fileId=FILE ID HERE, moduleCode=ABC}, {moduleCode=ABC, fileId=FILE ID HERE, group=Grp 03.csv}, {fileId=FILE ID HERE, moduleCode=ABC, group=Grp 02.csv}]}

Files to loop through and organise
Files to loop through and organise

Tuesday 17 January 2023

Organise files into a JavaScript Object

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"]}

Files to loop through and organise
Files to loop through and organise

Tuesday 3 January 2023

Bulk add files to existing Google Drive folders

The following Google Apps Script tool is designed to take a Google/Shared Drive folder full of files that you want to make a copy of and place into another set of existing Drive folders.You can decide if you want the subfolder name appending/prepending/ignoring in the file name of the new copy to help make it unique.

The tool will iterate through a single level of folders (not sub-subfolders) and for each one place a copy of the files into it.

Complete the information on the 'Welcome' sheet to set the tool up.
Bulk add files to existing Google Drive folders