How to Get Every Editor on Every Google File I Own
Learn how to find every Google Drive file you've shared with editors, including spreadsheets and documents, using Google Apps Script. This tutorial provides a step-by-step guide to retrieve and manage your shared files effectively.
If we are looking for old sheets or old documents that we've shared with someone, I'm gonna show you how to find every single sheet or document or every Google Drive file you've ever shared with someone who is an editor . Not just viewer , but editor . Meaning this is useful for two things, one. Have sheets that I give away a lot, and sometimes people request access to them and if they request editor access, I may not see that and I might just click approve, not change it to view. So some errors may happen through actual human error that says, Hey, I've given edit access to someone for the sheep that I didn't mean to, or I'm just looking for the editor of. A sheet or an old sheet that I don't remember the name of, like, but I remember the person that is working on that with me.
And that doesn't come up in Google Drive search, so let's just look through every single sheet I've ever edited with someone else. I'm gonna show you how to do this. So here's a list of literally the sheet, URL, the email of the person and the name of the sheet so that I can see who it is. So let's go over to extensions abs script. We're gonna write a little bit of abs script, but I'm gonna walk you through every single step and we're gonna get the whole thing done fairly quickly. We're gonna get editors rename that our function is gonna be get editors and the very thing, very first thing we wanna do is variable sheet equals spreadsheet . App dot get active spreadsheet dot get sheet by name. We need to put parentheses here, get sheet by name and we're gonna get editors.
Now, the whole structure of this is we're gonna get, get my email, get all files in Google Drive, owned by me. We're going to then go through each file. Get the editor . Actually, we're gonna get the list of editors if they match . So I'll put it down here if they match me. Ignore, but anyone else get the name? URL and email address. Put it in the editor 's tab. So that's why we need the editors. 'cause ultimately we're gonna put it in there. Okay? So that's all we're gonna do. Let's get our own email. This is pretty simple variable. My email equals. Now we could do the owner of this particular spreadsheet , but we could also do session.
Get active user, get email. That's me. Or whoever's using this, maybe there's someone else using this. We wanna get all the files, so it's variable files equals drive, app, do search files. Now the search, this is going to be the most interesting part in double quotes. We're gonna put in single quotes. Me in owners, that is it. Now this is equivalent to going to Google Drive. And in the top, like drive.google.com, yourself and in the top writing Owner Me and just searching for that. So you cannot put Owner Colon me here as the search because this is a slightly different search. It's sort of searching in A SQL format , whereas on Google Drive itself,
if you just go to drive.google.com and you search for Owner Me, that's the correct operator to manually search for it. But this is it. In this search files. I think that's very interesting. So while files has next, now this is interesting because every single result of this files is going to have a next, except for the last one. So every, it's basically gonna give you a really long list of files. However many files you have, and then you check that has next. And if it's true, we're gonna do this. So as long as this is true, as long as we have files, and at the very end it's gonna say there is no more files. So it's gonna be false and it's gonna stop. So this is like a for loop, but it's called a while loop.
And our file is equal to files next. And I know this sounds super complicated and this sounds like sort of a little wrong, that your. Current file is the files next, but that is how it's done when you're going through this Drive app. And this is a little in obvi, unobvious, unintuitive, but it is or it works. Okay, so we have our file and now our sheet name of whatever file that is, or document name. Is equal to file.gi name, very simple variable sheet URL or the URL of any file we get here is file. Get URL. Our editors are editors equals file GI editors.
Very simple. Right now if you wanna do other things, file dot get, you can see there's other. Options here, you can get the ID last updated. You can get who the owner is, but in this particular case it's gonna be all of ours 'cause we're searching for all of the sheet, all of the files that have us as the owner . But there's some other things here that you might want to get. But for these purposes, we're just going to do this. So now we need to loop through each of the editors. So we are gonna go through editors dot four each. And here it's a little weird, but this is going to be a variable name. This editor is actually any word we want. We're gonna do this arrow function and inside of here we're gonna do curly brackets and say the email equals editor do get email.
Again, this editor word here is any variable we want. And we just say basically there's a list of editors, there's some results. We're gonna name them, editor or anything. And then from that we're gonna get the email. And here's a trick we can say, if email is not equal to my email. And then end parentheses. Then we're gonna have a curly brackets. So if it's not my email, I want to do sheet, which is this editor sheet upend row. And in square brackets, we're gonna have three things, which we set up here. We're gonna have our sheet, URL, email of the person and the sheet name . So at the very end, let's do spreadsheet app. Do get UI alert, Hey, we're done.
Save all of that. We're gonna run it and it's gonna ask us for a approval review permissions. Gonna continue. Once we've selected our account, click continue. It's gonna ask us this the very first time we do it, that authorization has to run, but now every time we do it, it's not going to ask us and it's starting. So this was the like sort of a dummy version, but. It is rolling through, trying to find them all. Let's put a logger here just so we see what's going on. We'll save this and run. And we can see it's going through every single file. So it's gonna go through a bunch. And there it's found a bunch of spreadsheets of mine. Put them in this sheet. There we go. And this is great for finding any files in your Google Drive or Google Workspace. I actually, by running this, I found a video that is over a gigabyte
that I had shared with someone and said, Hey, download this. And then I didn't delete it after they had downloaded it. They had confirmed they downloaded it, and then I wanted to delete it, and I never did. So this saved me a gigabyte of Drive space. Really awesome. Really great to see all of the sheets I've ever made, or even every document, everything. One extra thing you might wanna do in case you have a lot of files and you're only looking for spreadsheet files or even document files. I'm gonna add a line here. Basically we're gonna say variable files, same as me and owners, except we're going to add a mine type. Inside of the quotes, we can say and mime type equals. And in single quotes, there's a little complicated, but it's gonna be application slash bnd.google
apps spreadsheet . Now this will only look in spreadsheets and we'll copy and paste this and look in. Document. So this will only look in document so you can edit this back in. In replacement of this being owners, if you wanna only look in documents, only search documents, and this one only search spreadsheets. There you go. So I'll delete the other. Comments and format this document. There you go. So you can get the this link to the sheet down below. And if you're interested in doing more coding and really don't know where to start on better sheets, there's a course called Spreadsheet automation 1 0 1. That plus a bunch of other courses are called Master
Spreadsheet Automation on Udemy. So on Udemy, there's master spreadsheet automation that includes. Spreadsheet automation 1 0 1 and other courses available on better sheets, so wherever you are, if you wanna get the course standalone, get it at Udemy or get it here on Better sheets.co. Over at spreadsheet Automation 1 0 1. I. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is gonna be your next Google sheet.