Last active
May 24, 2017 11:36
-
-
Save rheajt/f9bb0b335e39045531012b3fb6f5cf6d to your computer and use it in GitHub Desktop.
copy titles into all documents in a folder
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
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