From the course: Google Apps Script for JavaScript Developers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
File iterators - Google Docs Tutorial
From the course: Google Apps Script for JavaScript Developers
File iterators
- [Instructor] Now what happens if you want to find a file by its actual name? As I mentioned earlier, there could be multiple files with the same name whether inside of a particular folder on Google Drive or throughout the entire Google Drive itself. Let's go ahead and create a utility to help us find the first file that exists based on the name we supply. We'll go into our util script and let's go ahead and delete this function. Now we'll create a new function and we're going to call this function findFileByName and we'll pass in name as an argument. Let's create a new variable called files because there may be multiple files with the same name. We don't know how many files we're actually going to get. We'll set this variable equal to DriveApp.GetFileByName. As you can see in the code completion, instead of getting a reference to a file, we're actually going to get a reference to something called the file iterator. A file iterator is a collection of files that are contained based on…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.