Get google drive folders/subfolders

:bullseye: What is your goal?

I have a fitness program wich im using Google drive to store my clients info for their Diet/training plans, but im trying to automate these plans because it takes a lot of time.

:thinking: What is the problem & what have you tried?

The problem is im trying to figure out how to take the last diet file from each client i got.

Example with Folders: Client Alana/ Diet plan N1, Diet plan N2, Diet plan N3

How do i reach to these files and how do i get the ID or get the last diet wich in this case is ‘‘Diet plan N3’’, I tried using my first module of Google Drive search Files/Folder, on wich i could get the ID of the folder of each Client. But with the next module of Google drive search files/folder, i can’t get that last file, i’ve tried everything i know + using some IA with Gemini. Is there any easy way to get that last file.

Forgot to mention that every client are inside a big a folder named ‘‘clients’’, also the files are google doc and i dont have only google docs on every client, i got also other type of files.

:link: Create public scenario page

Hey Dobromir,

do the files follow the same naming convention? Do they always end with N#?

You can use last(split(file_name;space)) to get the N# of the file. Then replace() on top of that to replace N with {{emptystring}} and this will give you the file number.

Aggregate the resulting numbers along with the corresponding file names in an array and sort it to get the largest one. Or skip the file name if you only care about the number to create the next file.

Hi @Dobromir_Georgiev_To

First, restrict the search of module 15 to the “clients” folder. Map the Google Drive ID of that folder in the Choose a Folder field.

Then just use the name of the sub-folder as the Query, as you are doing. Make sure they match perfectly. Note that you’re mapping an array item withour an index to the Query field. The value will be the first item of Cliente[]. Make sure that’s what you want.

Then, for module 25, you need to set the Id you just retrieved for each client folder in the Folder ID field, in order to search for files inside that folder.

Now comes the tricky part. Google Drive Search for Files/Folders module doesn’t have an orderBy option, so you have two options:

  1. Get all the files inside that folder that match your restrictions (Google Docs filetype only, name contains ‘Diet Plan’, not deleted), aggregate them, then sort by last modified date and extract the first one. Somethinmg like this:

Make sure you choose Enter custom search query and paste in mimeType = 'application/vnd.google-apps.document' and trashed = false and name contains 'Diet Plan'

To get the first entry, use this: {{first(sort(4.array; "modifiedTime"; "desc"))}}


OR

  1. Use Google Drive Make an API Call and solve it all with one module:

Watch out for the 'folder id' in parents.

I would choose option #1, since you don’t have to worry about Google API changing and breaking your scenario. That’s what Make is for.

@damato

2 Likes

Thank you Damato, i finally could get what i need, 10/10

2 Likes

Thank you so much for coming back here to let the community know, Dobromir! :slight_smile:

2 Likes