Skip to content

Instantly share code, notes, and snippets.

@palumbo
Created August 5, 2023 16:50
Show Gist options
  • Save palumbo/d81f9541a8ee0829420c97a2a55936c3 to your computer and use it in GitHub Desktop.
Save palumbo/d81f9541a8ee0829420c97a2a55936c3 to your computer and use it in GitHub Desktop.
This Google Apps Script creates folders and files in Google Drive based on values in Google Sheets
function myFunction() {
// Spreadsheet Variables
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var lastRow = sheet.getLastRow();
// Google Drive Variables
var rootFolder = DriveApp.getFolderById("1oqHxYeC8wC0ufJ8WPtq4WKfoJDqulppB");
// Logger.log(lastRow); << 18
for ( var i = 1; i < lastRow; i++ ) {
// create folder
let title = sheet.getRange(i,1).getValue();
let description = sheet.getRange(i,7).getValue();
if ( title != "title") {
var folderId = rootFolder.createFolder(title).getId();
var folder = DriveApp.getFolderById(folderId);
// Logger.log('Folder Name: ' + title + ' Folder ID ' + folderId);
var docID = DocumentApp.create(title).getId();
var document = DocumentApp.openById(docID);
var paragraph = document.getBody().appendParagraph(description);
DriveApp.getFileById(docID).moveTo(folder);
};
}
}
@palumbo
Copy link
Author

palumbo commented Aug 14, 2024

Hi @amitm020, yes, you can use ui.prompt to get input from a user, then use that input as a value/parameter in your code.

Everything you currently do with your bat script can be duplicated with Apps Script.

@amitm020
Copy link

amitm020 commented Aug 14, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment