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 Dec 13, 2023

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

@amitm020
Copy link

Hi

@amitm020
Copy link

Can you make a script with prompt for making folder names and then make folder names with the prompt. I have made a bat exe which runs on command prompt, it asks for

  1. Deal Number
  2. Deal Name
  3. Seller
  4. Customer

Based on above information, Parent folder is created with
Parent folder - "Deal Number" + "Deal Name", under this
1st Folder is "Deal Number"+"Deal Name"+"Customer" then "Deal Number"+"Loading Pics"
2nd folder "Seller" then "Deal Number"+"Loading Pics" and "Material Pics"

Loading Pics and Material Pics is static.

In the 2nd folder, a xlsx file is copied and renamed to "Deal Number"+"Shipping Instructions".xlsx

This script can be run on a windows system only, I am planning to shift to chromebook, so I want a script which is platform independent.

@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