Last active
April 2, 2021 15:21
-
-
Save barrieroberts/bbe97ffda6e21cc1a20793a2cc3b68f0 to your computer and use it in GitHub Desktop.
11-search files and folders
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
//search for files | |
function example111() { | |
const files = DriveApp.getFolderById('ADD YOUR FOLDER ID HERE') | |
.searchFiles('modifiedDate > "2021-03-31"'); | |
while (files.hasNext()) { | |
var file = files.next(); | |
Logger.log(file.getName()); | |
} | |
} | |
//search for files - multiple search terms | |
function example112() { | |
const files = DriveApp.getFolderById('ADD YOUR FOLDER ID HERE') | |
.searchFiles('modifiedDate > "2021-03-01" and title contains "folders"'); | |
while (files.hasNext()) { | |
var file = files.next(); | |
Logger.log(file.getName()); | |
} | |
} | |
//search for folders | |
function example113() { | |
const doc = DocumentApp.create("Folders list"); | |
const folders = DriveApp.getFolderById('ADD YOUR FOLDER ID HERE') | |
.searchFolders('title contains "folder"'); | |
while (folders.hasNext()) { | |
var folder = folders.next(); | |
Logger.log(folder.getName()); | |
doc.getBody().appendParagraph(folder.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment