SHARE
TWEET

Untitled

a guest Jul 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Log the name of every folder in the user's Drive
  2. function example71() {
  3.   const folders = DriveApp.getFolders();  
  4.   while (folders.hasNext()) {
  5.     var folder = folders.next();
  6.     Logger.log(folder.getName());
  7.   }
  8. }
  9.  
  10. //Get folder names within a specific folder
  11. function example72() {
  12.   const parentFolder = DriveApp.getFolderById('ADD FOLDER ID HERE');  
  13.   const folders = parentFolder.getFolders();
  14.   while (folders.hasNext()) {
  15.     var folder = folders.next();
  16.     Logger.log(folder.getName());
  17.   }
  18. }
  19.  
  20. //Change all folder names within a specific folder
  21. function example73() {
  22.   const parentFolder = DriveApp.getFolderById('ADD FOLDER ID HERE');  
  23.   const folders = parentFolder.getFolders();
  24.   var n = 0;
  25.   while (folders.hasNext()) {
  26.     var folder = folders.next();
  27.     n++;
  28.     folder.setName("FOLDER "+n);
  29.   }
  30. }
  31.  
  32. //Get specific folder by name, get its ID
  33. //make a copy of a file and add it in that folder
  34. function example74() {
  35.   const parentFolder = DriveApp.getFolderById('ADD FOLDER ID HERE');  
  36.   const folders = parentFolder.getFolders();
  37.   while (folders.hasNext()) {
  38.     var folder = folders.next();
  39.     if(folder.getName() === "FOLDER 3"){
  40.       var folderId = folder.getId();
  41.       var folder3 = DriveApp.getFolderById(folderId);
  42.       const masterFile = DriveApp.getFileById('ADD FILE ID HERE');
  43.       masterFile.makeCopy("New Doc", folder3);
  44.     }
  45.   }
  46. }
  47.  
  48. //Get file names in a folder
  49. function example75() {
  50.   const parentFolder = DriveApp.getFolderById('ADD FOLDER ID HERE');  
  51.   const files = parentFolder.getFiles();
  52.   while (files.hasNext()) {
  53.     var file = files.next();
  54.     Logger.log(file.getName());  
  55.   }
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top