Created
September 25, 2020 18:57
-
-
Save leoherzog/5843be91f32bfc3d9b97fe028d1a0c64 to your computer and use it in GitHub Desktop.
Google Drive Photocopier - Make lots of copies of a file in Drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (copy this into a new Apps Script project - https://script.google.com/) | |
// Hello! | |
// | |
// To make lots of copies of a thing in Google Drive, | |
// put the ID or URL of the Google Drive file here: | |
// | |
var fileToCopy = "https://jamboard.google.com/d/1jwdBuEjFtGvAjaRIsxXkR-nm-EgL2cES8UGOjREvdj0/viewer"; | |
// | |
// Quotes are important! Example: | |
// var fileToCopy = "https://docs.google.com/document/d/1TIDOiUpPiWNqKqduKlbtm2O4jgFIAPrxuz_JFWzod9s/edit?usp=sharing"; | |
// | |
// Then just specify how many copies you want (no quotes): | |
// | |
var numberOfCopies = 2; | |
// | |
// Example: | |
// var numberOfCopies = 5; | |
// | |
// and the ID or URL of the folder you want to put it into (or just "" for the main "My Drive" folder): | |
// | |
var destinationFolder = ""; | |
// | |
// Example: | |
// var destinationFolder = "https://drive.google.com/drive/folders/1N3YyOsktaNGNCFBof3mgNNEpHyXiIjr-"; | |
// or | |
// var destinationFolder = ""; | |
// | |
// | |
// Then press the "Play" button in the toolbar above! | |
// | |
// | |
// | |
// | |
function makeCopies() { | |
try { | |
fileToCopy = DriveApp.getFileById(fileToCopy); | |
} catch(e) { | |
try { | |
fileToCopy = fileToCopy.match(/[-\w]{25,}/)[0]; | |
fileToCopy = DriveApp.getFileById(fileToCopy); | |
} | |
catch(e) { | |
throw "Sorry, trouble opening that file. Is that an ID or URL of a file in Google Drive that you have access to?"; | |
} | |
} | |
if (destinationFolder === "") { | |
destinationFolder = DriveApp.getRootFolder(); | |
} else { | |
try { | |
destinationFolder = DriveApp.getFolderById(destinationFolder); | |
} catch(e) { | |
try { | |
destinationFolder = destinationFolder.match(/[-\w]{25,}/)[0]; | |
destinationFolder = DriveApp.getFolderById(destinationFolder); | |
} | |
catch(e) { | |
throw "Sorry, I didn't understand that folder. Is that an ID or URL of a folder in Google Drive that you have access to?"; | |
} | |
} | |
} | |
let i = 0; | |
while (i < numberOfCopies) { | |
fileToCopy.makeCopy(fileToCopy.getName(), destinationFolder); | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment