Members-only tutorial

Watch the video and get the practice sheet with membership.

See membership options

Every Google Drive File Created in Last 24 Hours

About this Tutorial

Create a simple report in a Google Sheet that documents every file in your Google Drive that was created in the last 24 hours.

Video Transcript

<div>00:00 Here's every single drive file created in the last 24 hours in my Google Drive. Here is the Apps Script Learn about Apps Script and how it can automate tasks in Google Sheets. Opens in new tab to do that.<br>00:07 Ah, but we're gonna do something a little bit different and we're gonna edit this and make this way easier to use.<br>00:14 But if you don't trust me, let's do sheet.new slash 3 and create a new sheet. We'll call this new sheet and let's see if it runs, if we run this trigger Discover how triggers can automate your scripts based on events or time. Opens in new tab , if it runs.<br>00:27 So we go into drive created, run and it's going to append everything. So there it is, new sheet.

And now every time I run this it's gonna append to the sheet so it creates these files again or at least these lines again.<br>00:41 Where Understand the WHERE clause in queries to filter your data effectively. Opens in new tab did I get this? I got this from Digital Inspiration. Ahmit is fantastic.

He created this originally, but we're going to edit this and make sure that we can use it to track our basically any files created, modified, but for first I want to show you what his function Get to know functions in Google Sheets and how to use them. Opens in new tab looks like.<br>01:03 His function Get to know functions in Google Sheets and how to use them. Opens in new tab looks like this which is drive modified report and what it does is it looks for everything that's modified.<br>01:10 If you can see here it says modified date is greater than whatever the start time is one day ago.

And so we can run this every 24 hours.<br>01:20 We can try to create an email from this and say hey here's all the modified em uhm sheets and actually everything in our drive.<br>01:28 So even if we do doc.new let's keep it as untitled. Let's delete everything here and run the modified one. So let's see, actually just create it again.<br>01:41 Let's do that and you'll see. Is it on? Ah, we are offline. Okay, we're back online. Let's try, I think it needs to actually have something in here, not just blank.<br>01:57 So let's run modified again, or sorry create it again.

And it will say, there it is, untitled. So, if we run this every 24 hours, every single time we create a file it'll show up.<br>02:10 But, the one that actually Amit created was drive modified. And it says modified date, one day ago, and we want to be able to edit these things.<br>02:21 So, I'm going to show you in this video how to edit these things and how to create the one that I did, which is, um, the created report.<br>02:27 Um, so, we'll start with this and we'll walk through it a little bit.

We get the active spreadsheet Find out what the active spreadsheet is and how to reference it. Opens in new tab , we're just getting the sheet that we're on right now.<br>02:38 We're getting the current time zone Learn about time zones and how they affect your data and scripts. Opens in new tab where Understand the WHERE clause in queries to filter your data effectively. Opens in new tab where Understand the WHERE clause in queries to filter your data effectively. Opens in new tab we are. We create a new date and then we say, okay, a new date one day ago is just today minus this many milliseconds.<br>02:49 So, it's one day times 24 hours times 60 minutes times 60 seconds times 1000 milliseconds. And that gets us one day ago, so literally 24 hours ago.<br>02:58 That's our start time.

And then we're going to go through the Drive app and do a driveapp.search files and what the search is going to be is that it's either trashed, yes or no, and the modified date is going to be greater than whatever one day ago is in milliseconds.<br>03:17 So, this modified date is in this like millisecond time. Uhm, and then it will go through each and every file, it will get ah, this is just the list of files, files, and this dot has next and next is pretty complicated or rather confusing sometimes.<br>03:35 When we're searching through Drive app files, it will give us one file.

Then we have to say, does it have a next one, yes or no, and if it has a next one, then we go to the next one, dot next, and that one, we are going to get the name, the URL, and the date created here, which actually this is date&nbsp;<br>03:55 modified, even though it says the variable is date created, it's actually date modified, uhm. And so, sorry, that actually is the date created, sorry, my, my bad.<br>04:08 This modified date is the actual modified date.

But in order to only get the, uh, files that are date created within the last day, what I did is, I added, uh, a if statement here.<br>04:22 And I said, if the date created is greater than the start time, we are going to only then, and if it's greater than the start time, actually append the file.<br>04:36 So, let's look at what is the modified one. So, you'll see modified has a lot. So we'll Select Explore the SELECT clause in queries to choose specific data. Opens in new tab our modified and run it.<br>04:41 Uhm, it's anything that's been edited by me, by a script. It's a ton of things that are like, even shared files in my drive.<br>04:50 This is a lot of stuff.

And it was like way too much, because it's a lot of sheets that like, someone else modified, but it's shared with me or in my inbox.<br>04:59 Like this one million checkboxes is a video I made where Understand the WHERE clause in queries to filter your data effectively. Opens in new tab it's literally a million checkboxes, a million cells Understand how to work with cells in Google Sheets. Opens in new tab , a million checkboxes.<br>05:04 And if anyone edits that, ever, because anyone has edit access Learn about edit access and how it affects collaboration in Sheets. Opens in new tab , uhm, this will show up in here. Uhm, there's all types of stuff.<br>05:13 So I didn't want all of these. I didn't want this entire report.

I wanted only the ones that were create, actually created.<br>05:23 What this allows me to do is run this report and I can then see what is, this is great for like time tracking, uhm, also if you lose files in your drive and you're like, oh, I need to find that file that I just created today, uhm, but it's untitled.<br>05:40 Which one, one of these untitled documents is it, uhm, that will show up here, but I want to stop having to go over to my, uhm, Apps Script Learn about Apps Script and how it can automate tasks in Google Sheets. Opens in new tab and run this, so let's create a little bit of a menu and we're going to go to snippets.<br>06:00 BetterSheets.co slash snippets, we'll find this custom menu Create custom menus in Google Sheets to enhance functionality. Opens in new tab one, we're just going to copy this, uh, code.

And we're going to enter it here in a function Get to know functions in Google Sheets and how to use them. Opens in new tab unopen, only one unopen can exist, we're going to create a report menu here.<br>06:14 The first item is, we're going to get created report. And the second one is going to be modified report. And all we have to do is put in the second argument Discover what arguments are and how to use them in functions. Opens in new tab here, the actual function Get to know functions in Google Sheets and how to use them. Opens in new tab name, there we go, save that, make sure it's saved, and now we refresh the sheet, and we will have We have a report here<br>06:39 , notated. And now we can say, OK, I just want to create this. Uh, I do author, need to authorize it, OK.<br>06:47 Very first time I run it.

Through here, let's do it again. And it's just going to append. So that's one thing is I can always now save this as like, oh, created on Tuesday.<br>07:00 Tuesday, July 23rd. There you go. Now, if I want to create a new report, just hit plus. Now I'm on a new sheet. Now I want modified report.<br>07:11 And now I can take this exact same name once it's done. And I can quickly say my name. Modified.

So this is great also if you are trying to keep track of time or projects and say what did I modify today.<br>07:28 If you're doing this for a boss, if you're doing this for a company and you're like hey I need to just prove that I modified these sheets or these documents today on this day.<br>07:37 Uh and we have this here as a report. One good thing. Another good thing about appending these as well is that what we can do is instead of having just these individual reports we can say uh created.<br>07:51 Let's do that.

And now this is the act of, we can change, oh my god I need to move, why can't I move this over.<br>08:02 Let's just move this back. Okay, so now instead of appending to the active sheet Learn about the active sheet and how to manipulate it. Opens in new tab I want the script to just append to create it.<br>08:11 And I want to run this report every single day. So I want to show you how to automatically do that.<br>08:16 Again we have this drive created report. I'm going to actually copy this so that you have everything, all of these functions Explore various functions available in Google Sheets. Opens in new tab separately.<br>08:26 But instead of drive created report on created tab. That's what we're going to do.

We can add this to our UI, add this to our menu if we want and I will do that now.<br>08:39 I'll show you the whole process. I'm going to add item, add to created and we'll take the function Get to know functions in Google Sheets and how to use them. Opens in new tab name and move it here.<br>08:50 Or not move it, but copy it there. Make sure it's all caps created and instead of get active sheet Learn about the active sheet and how to manipulate it. Opens in new tab , we are going to do dot Get sheet by name, so easy, created.<br>09:04 That is it. So now every single time I run this, I will append to the created tab.

So let's run, actually let me show you that it is in the menu and let's test it before we do our um automation.<br>09:22 I always like to test it, add to created. We'll run it and there it is. So even if I'm on this tab, add to created, it finished it, it added here.<br>09:36 Let's do just Just in case, I was going to say activated, but we don't need to in this case. We want to trigger Discover how triggers can automate your scripts based on events or time. Opens in new tab this every day to just keep adding all of these documents that we've added, created.<br>09:49 How do we do that?

We're going to go over to our triggers, but before we go there, I want to double remind you the function Get to know functions in Google Sheets and how to use them. Opens in new tab is called drive created report on created tab.<br>09:58 That is the function Get to know functions in Google Sheets and how to use them. Opens in new tab that we're going to use. Automate. Go over to the tab triggers on the left side. On the bottom right, add trigger Discover how triggers can automate your scripts based on events or time. Opens in new tab .<br>10:07 Which function Get to know functions in Google Sheets and how to use them. Opens in new tab are we going to run? We're going to run drive created report on created tab. We are going to select Explore the SELECT clause in queries to choose specific data. Opens in new tab instead of an event source from spreadsheet Understand what a spreadsheet is and its components. Opens in new tab , we're going to select Explore the SELECT clause in queries to choose specific data. Opens in new tab time-driven.<br>10:18 And here, we're going to select Explore the SELECT clause in queries to choose specific data. Opens in new tab every single day.

It's going to run, let's say we want to run it just after midnight, but before we start work the next day.<br>10:28 Um, and it's going to capture everything within the last 24 hours, right? So 2am to 3am is a good time that it captures generally that day.<br>10:37 We could absolutely do midnight to 1am, but I do find, and this is common in some industries, that people will work beyond midnight, but expect that that work is reported on for the day before midnight, if that makes sense.<br>10:55 So I will say maybe even like 3 to 4am or 4 to 5am.

If you want to be really sure, no one's burning the midnight oil, but let's do 2 to 3am, save.<br>11:08 And now we know that we triggered this while the spreadsheet Understand what a spreadsheet is and its components. Opens in new tab was open and we used it.

I'm going to allow this to run for a day or two and see if it works and I'll come back.<br>11:18 If there's any errors, it'll show up here and we can always fix also go over to executions and see if there's any errors here.<br>11:25 Errors that may occur are include like no rows left, like if it's appending a row it probably will not happen, so let's even test that out.<br>11:36 Let's just delete all of the rows there and run it and see if we get an error Learn how to troubleshoot common errors in Google Sheets. Opens in new tab .

It probably won't because it's using the function Get to know functions in Google Sheets and how to use them. Opens in new tab append row.<br>11:44 I do know that sometimes when writing code and we don't use append row we just go say like go to last row plus one and add the data Get insights into managing and analyzing data in Google Sheets. Opens in new tab there, we are finding last row adding one and if that next last row doesn't exist It will fail, but appending row will just go to last and append it.<br>12:05 Um this is really cool we can find every drive file created in the last 24 hours and automate it and we've also created this awesome report menu here where Understand the WHERE clause in queries to filter your data effectively. Opens in new tab we can run this report manually if we want.<br>12:17 Uh again thank you to Amit Agrawal.

Thank Amit Agrawal for the original Apps Script Learn about Apps Script and how it can automate tasks in Google Sheets. Opens in new tab and hope you enjoyed these modifications we did to the Apps Script Learn about Apps Script and how it can automate tasks in Google Sheets. Opens in new tab .<br>12:27 Bye.</div>