The method for doing this is actually part of the bmFolderFun library documented in A handier way of accessing Google Drive folders and files from Apps Script but it can be really useful for keeping your Drive clean that I thought it deserved its own article. The idea is that given a path like /data/images you should be able to easily enumnerate all files, optionally filtered by type, and optionally including any subfolders. Once you know what you have and where it is, it makes everything a lot easier to organize.
Simple non recursive list
Let’s say you want to get a list of all files in a folder on drive. We’ll start with ignoring subfolders
The result is already quite useful as we’ve got the filenames, paths, and Ids for both the folders and the files.
Handier though if we can just look at files of a particular type
Handier still if we can look at subfolders as well, and combine that with selective mime types. This one will find any images in the given folder or any of its subfolders
and a little bit of the result
You may just want to know how many there are in all the subfolders (the answer was 81)
Counting by folder
You can manipulate the results- for example do a count by individual folder
Writing to a sheet
All that would be more useful if we wrote it to a sheet, and of course, there’s a library to turn the whole thing into pretty much a one liner, using Handly helper for fiddler
Here’s the code to discover and write the details of all my public published scripts to a spreadsheet
and here’s a sample of the sheet it created