Skip to content

Instantly share code, notes, and snippets.

@rheajt
Last active May 24, 2017 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rheajt/f9bb0b335e39045531012b3fb6f5cf6d to your computer and use it in GitHub Desktop.
Save rheajt/f9bb0b335e39045531012b3fb6f5cf6d to your computer and use it in GitHub Desktop.
copy titles into all documents in a folder
function copyTitles() {
//Replace this variable with the folder id
//you can get the id from the URL
var folderId = 'REPLACE_WITH_FOLDER_ID';
var folder = DriveApp.getFolderById(folderId);
var files = folder.getFilesByType(MimeType.GOOGLE_DOCS);
//this will iterate over every single DOCUMENT in that folder
//it will ignore spreadsheets, forms, and other files
//you can modify the mimetype above to change that behavior
while(files.hasNext()) {
var file = files.next();
var fileId = file.getId();
//this script takes the file name and inserts it into the very
//top of the document.
var fileName = file.getName();
DocumentApp.openById(fileId).getBody()
.insertParagraph(0, fileName)
.setAlignment(DocumentApp.HorizontalAlignment.CENTER)
.setHeading(DocumentApp.ParagraphHeading.HEADING1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment