Create a gist now

Instantly share code, notes, and snippets.

@rheajt /
Last active May 24, 2017

What would you like to do?
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 =;
var fileId = file.getId();
//this script takes the file name and inserts it into the very
//top of the document.
var fileName = file.getName();
.insertParagraph(0, fileName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment