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);
};
}
}
@vilas-92
Copy link

thanks for shearing code

@palumbo
Copy link
Author

palumbo commented Dec 13, 2023

@vilas-92 you're welcome. Thanks for using it!

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