The problem with Drive is that it's really easy to have loads of files with the same name spread around in multiple folders on Drive. Heres how to get a handle on that, without having to write a bunch of code. I'll be using the cUseful library, specifically these techniques.
Here's the key for the cUseful library, and it's also on github, or below. Mcbr-v4SsYKJP7JMohttAZyz3TLx7pV4j The objective is to write a report to a spreadsheet of files that are duplicates. On my private version of this, I also have an algorithm for cleaning them up, but I'm not releasing that for now as I don't want you to accidentally delete files you didn't want to, so this version concentrates on reporting on duplicates. It's pretty slow to look through thousands of files organized by many folders, so you may need to do it in chunks by using the /path setting, as well as particular mimetypes, and perhaps by using the search terms too. I'm using caching to avoid reading the folder structure too many times. It's a big job to do that, so the first time you do it it will take a while. If your folder structure is not changing much, you can set the cache stay alive time to a higher number. SettingsIt starts with the settings, which look like this var Settings = (function(ns) { ns.drive = { dapi:DriveApp, // Use DriveApp api startFolder:'/', // folder path to start looking mime:"application/vnd.google-apps.script", // mime type to look for recurse:true, // whether to recurse through folders acrossFolders:true, // whether to count files with same name in different folders as duplicate acrossMimes:false, // whether to count files with same name but different mimes as the same useCache:true, // whether to use cache for folder maps cacheSeconds:60*60, // how long to allow cache for search:"" // can use any of https://developers.google.com/drive/v3/web/search-parameters }; ns.report = { sheetId:"1Ef4Ac5KkipxvhpcYCe9C_sx-TnD_kvV2E_a211wS6Po", // sheet id to write to sheetName:'dups-'+ns.drive.startFolder+"-"+ns.drive.mime, // sheetName to write to min:2 // min count to report on }; return ns; })(Settings || {}); Here's an example output. Here I can see duplicate files names for scripts across folders. Some notes on the Settings
|
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Google Apps Scripts snippets >