I haven't written any tech pieces in a while, so as I was getting ready to write the monthly musical wrap up for February, I ran into this relatively simple problem that I had to write my own solution for. I did some googling and did not find anything particularly useful, so I imagine there will be other people trying to do this very thing. So, if that is you, looking for an easy way to pull the file names out of a specific Google Drive folder into Google sheets, today is your lucky day. It only takes a few lines of code.
So what exactly is the use case? Well, every month, I like to release a blog post about, among other things, the new songs that were added to our radio broadcast. OK, great. In the past I just had a local folder on my laptop that I was copying the MP3s into as I was also adding them to the radio playlist. But, to be fair, that is a little bit old-school at this point. I am still not a fan of the Apple backup process through iCloud, and only keeping your files on a single laptop is a recipe for disaster. So last year I transitioned into using a Google Drive folder. In a new sub folder every month, new songs now go there instead and I don't have to worry about backing up the laptop. But of course, you end up needing to copy a list of those songs as text into the blog post, and that's where things get tricky. On a local folder, you can shift-click to select any number of files, and then using the clipboard copy function, just pasting that into a text editor gives you a list of the files as text. But you can't do that with Google Drive. That feature is just not available.
For longer than I would like to admit, I have just downloaded the entire contents of the Google Drive folder in question and used that same solution—copying the local files into a text editor—as a functional, if tedious, work around. As I plan to discuss a little bit in coming weeks, I am finally getting around to taking care of some of these medium to low priority issues, and last night I finally found the time to devise a solution. I continue to be pleasantly surprised with the power of Google Apps Script. I use it at work as well to do some auto updates and to generally make the spreadsheet experience just a little bit more tailored to my specific needs—for example, I send an automatic timestamp to an adjacent cell when I add a note to any project sheets, which allows me to immediately understand which note has precedence when I go to a project that hasn't been front of mind for a few days. It's a godsend. If anyone wants me to post a breakdown of that solution, just ping me on mastodon.
There are a few reasonably helpful videos that I have found, but nothing specifically accesses a single folder with just the ID. If you want to search more broadly across the root folder with just keywords, or titles, then this is not for you. But if you just need a way to easily grab a text read-out of a list of files in one folder, this is how you do it.