Skip to content

Instantly share code, notes, and snippets.

  • Save mhakrook/d67f280b7c3e33623b64e495060bce7b to your computer and use it in GitHub Desktop.
Save mhakrook/d67f280b7c3e33623b64e495060bce7b to your computer and use it in GitHub Desktop.
function onSubmit() {
let ss = SpreadsheetApp.getActiveSpreadsheet()
let sheet = ss.getSheetByName("Form responses 1")
let sheetData = sheet.getRange(sheet.getLastRow(), 1, 1, sheet.getLastColumn()).getDisplayValues()
let date = sheetData[0][0]
let name = sheetData[0][1]
let level = sheetData[0][2]
let room = sheetData[0][3]
let problem = sheetData[0][4]
let imgID = sheetData[0][5].split('=')[1]
let imgFile = DriveApp.getFileById(imgID)
let responseFolder = imgFile.getParents().next()
let levelFolder
if(!responseFolder.getFoldersByName(level).hasNext()) levelFolder = responseFolder.createFolder(level)
else levelFolder = responseFolder.getFoldersByName(level).next()
let roomFolder
if(!levelFolder.getFoldersByName(room).hasNext()) roomFolder = levelFolder.createFolder(room)
else roomFolder = levelFolder.getFoldersByName(room).next()
let nameFolder
if(!roomFolder.getFoldersByName(name).hasNext()) nameFolder = roomFolder.createFolder(name)
else nameFolder = roomFolder.getFoldersByName(name).next()
imgFile.makeCopy(date, nameFolder)
responseFolder.removeFile(imgFile)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment