I need a reliable Google Sheets script that counts files in multiple Google Drive folders.
Requirements:
Goal:
I want a script that takes a folder link (or ID) and counts all items inside the specified subfolders. The count should stay updated as new files are added, and the script should handle future changes automatically.
Current Issue:
The script sometimes fails to read files — I can see files inside the folders, but the script returns a count of zero. I need the solution to be accurate and reliable.if it done one whole run than in second run it wont update that old data as folder file updated or removed.
Hi Mario Rossi — thanks for the detailed response. My requirement is slightly more specific based on my sheet structure.
Each row contains a main Google Drive folder link in column E.
Inside that folder there are multiple subfolders (e.g. Folder 1, Folder 2, Folder 3 … Folder 7, Others)
I need the script to:
• Recursively scan the main folder
• Count files inside each specific subfolder category
• Put counts in columns F onward (Folder 1 → Folder 7 → Others)
• If files are added later, counts should update correctly
• Ignore trashed files
• Ignore shortcuts (count actual files only)
• Count all file types
• Work in batches (50 rows per run)
• Automatically continue until complete
• Remove trigger when finished
• Log progress for troubleshooting
• Provide stable counts (currently they change each run)
• Allow periodic updates (e.g. hourly) so counts stay updated when files changeFolder classification logic:
• If file is inside subfolder named "Folder 1" → count in column F
• If inside "Folder 2" → column G
• … up to Folder 7 so onSheet name: use the existing sheet (first tab is fine)
Approximate size: around 8k–10k files total (may grow later).
Main requirement: counts must be consistent and reliable. Currently I get different values on each run, so stability is very important.
The sample sheet I shared reflects the structure I need.
Thanks — looking forward to the script.
Hi Sagar,
I implemented this using Google’s stable APIs directly, not Apps Script. So it is not limited by Apps Script execution time, trigger behavior, or quota constraints.
It can handle the workflow you described:
I also ran a working demo on your sheet structure. Please check this demo:
Demo sheet
If this is still useful for you, I can package it into a clean working version for your sheet.
Also, what would be a reasonable budget for you if this saves you from the current manual checking and unreliable counts?
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/CACrgDdqZzoeokCgcrF7y8E%3DSmGj8AEdh7ZP_1cV6MUT66gzGGg%40mail.gmail.com.
With kind regards,
Ben