Still struggling with listing files from Google Drive manually? I’ve been there too.

Still struggling with listing files from Google Drive manually? I’ve been there too.


I used to spend hours copying file names and URLs one by one. It was tiring, and let’s be honest, no one wants to do that! 😩

After some work (and more coffee than I’d like to admit ☕), I finally wrote a simple script to do it all for me. Now, I’m sharing it with you so you can save your time, too.

𝗛𝗼𝘄 𝗱𝗼𝗲𝘀 𝗶𝘁 𝗵𝗲𝗹𝗽?

– It lists all the files from a folder and puts their shareable URLs into a Google Sheet.
– Before using it, make sure your folder’s access is set to “Anyone with the link” so the script can create those shareable URLs.
– Due to time limits (around 6 minutes per run), I’ve set it to process 100 files at a time. After it finishes, just run it again if you have more files. Repeat as many times as needed until you have all your URLs.

function listFilesInFolder() {
var folderId = 'YOUR_ID_FOLDER';
var maxFilesPerRun = 100;
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

var props = PropertiesService.getScriptProperties();
var startIndex = parseInt(props.getProperty('lastProcessedIndex')) || 0;

if (startIndex === 0) {
sheet.clear();
sheet.appendRow(["File name", "URL for sharing"]);
}

var folder = DriveApp.getFolderById(folderId);
var files = folder.getFiles();

var currentIndex = 0;
var processedCount = 0;

while (files.hasNext()) {
var file = files.next();

if (currentIndex < startIndex) {
currentIndex++;
continue;
}

var fileName = file.getName();
var fileUrl = file.getUrl();

if (file.getSharingAccess() === DriveApp.Access.PRIVATE) {
file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
}

sheet.appendRow([fileName, fileUrl]);
processedCount++;
currentIndex++;

if (processedCount >= maxFilesPerRun) {
props.setProperty('lastProcessedIndex', currentIndex.toString());
Logger.log("Stop after " + processedCount + " files. The next launch will start with the index " + currentIndex);
return;
}
}

props.deleteProperty('lastProcessedIndex');
SpreadsheetApp.getUi().alert("It's done! The links are saved in the table.");
}


I’ll also share a video example, so you can see it in action.



This script is part of a bigger project I mentioned in previous posts, and it’s just one of the many tools I use to save time.

Hope it helps you too! Feel free to ask any questions.

Let’s make technical SEO a bit more fun and a lot more efficient!

Was this article helpful?
YesNo
 
Oleh Dankevych

Increase Your Website Traffic with Professional SEO Strategies!

Please enable JavaScript in your browser to complete this form.

Case Studies

Record: 432K Clicks and 162M Impressions in 12 Months

Record: 432K Clicks and 162M Impressions in 12 Months

Introduction to the Project Introducing a premier Canadian platform dedicated to providing high-quality visual assets, including photos, images, illustrations, and...

Explosive Growth in Visual Content 12-Month Success

Explosive Growth in Visual Content 12-Month Success

Introduction to the Project Introducing a premier Polish platform dedicated to providing high-quality visual assets, including photos, images, illustrations, and...

Minimal Spend Major Growth in 12 Months

Minimal Spend Major Growth in 12 Months

Introduction to the Project Leading Ukrainian platform dedicated to providing high-quality, eco-friendly products for families. Our offerings include a wide...

Technical SEO

Still struggling with listing files from Google Drive manually? I’ve been there too.
Technical SEO

Still struggling with listing files from Google Drive manually? I’ve been there too.

I used to spend hours copying file names and URLs one by one. It was tiring, and let’s be honest,...

SEO tool that transformed my life and could revolutionise yours too!
Technical SEO

SEO tool that transformed my life and could revolutionise yours too!

Thanks for reaching out and asking where I’ve been! Well, let me fill you in-first off, I ran out of...

Let me share a little story with you… how to save several thousand pounds…
Technical SEO

Let me share a little story with you… how to save several thousand pounds…

Not long ago, I was stuck in a never-ending cycle of manually checking structured data on hundreds (if not thousands)...

How to Easily Extract All URLs from Your Sitemap Using Python
Technical SEO

How to Easily Extract All URLs from Your Sitemap Using Python

Hello, SEOs! It’s been a while since my last post I’ve been revamping my setup and got myself a comfy...

Technical SEO (#5): How Can I Scoop Up All Links and Anchors in a Flash with Google Dev Tools?
Technical SEO

Technical SEO (#5): How Can I Scoop Up All Links and Anchors in a Flash with Google Dev Tools?

Hey there, fellow lazy website owners! Ever wished you could snatch up all the links and anchors from a webpage...

Technical SEO (#4): How Can I Grab All the Links from a Page?
Technical SEO

Technical SEO (#4): How Can I Grab All the Links from a Page?

Hey there, fellow lazy website owners! Want to get your hands on all the juicy links from a webpage without...

Technical SEO (#3): How can you give your website VIP treatment for users and bots?
Technical SEO

Technical SEO (#3): How can you give your website VIP treatment for users and bots?

Hey there, fellow website owners! Ever wondered how you can make your website shine bright for both human visitors and...

Technical SEO (#2): How to implement hreflang tags correctly on a multilingual website?
Technical SEO

Technical SEO (#2): How to implement hreflang tags correctly on a multilingual website?

Hey lazy website owners! 🛋️ Want to make sure your multilingual website speaks the language of search engines? It’s as...

Technical SEO (#1): How can structured data markup improve a website’s visibility in search results?
Technical SEO

Technical SEO (#1): How can structured data markup improve a website’s visibility in search results?

Hey there, fellow website owners! Ever wonder how some sites seem to pop up at the tippity-top of search results?...

Donation

Please support my project by donating today to help me continue delivering valuable content to our community.

Sign up for Dominate Google Rankings

Want better rankings? Get my step-by-step SEO guide.