How to get all the txt files in a folder in Google drive and its nested folders?

Hi all,
I have a folder, test1, inside my Google Drive. I want to extract all the ‘.txt’ files inside it and even from its subfolders. My eventual result should be :-

[

{

"kind": "drive#file",

"id": "1Z7DOvdNX2mMtP3EE1WSeXSkDZVAq9bGR",

"name": "1.txt",

"mimeType": "text/plain",

"webViewLink": "https://drive.google.com/file/d/1Z7DOvdNX2mMtP3EE1WSeXSkDZVAq9bGR/view?usp=drivesdk"

},

{

"kind": "drive#file",

"id": "1frN_6x883svdsBH2ZWNzP2hbX8va8COH",

"name": "Copy of Spring and SpringBoot Notes.txt",

"mimeType": "text/plain",

"webViewLink": "https://drive.google.com/file/d/1frN_6x883svdsBH2ZWNzP2hbX8va8COH/view?usp=drivesdk"

}]

Thanks in anticipation.

1 Like

Hi @Dhana_M,

You can search folders, then use an if statement to test if the folder is the one you are looking for or its parent has that id. If there are more sub folders within, you need to add parent[1], parent[2], etc.

Here’s a workflow for you.

If this answer solves your issue, plase mark it as the solution so others can benifit.

Best,

Robert

@rbreen thank you for the response. The subfolders are not static. Given a folder it may have any level of nesting and I am not sure how many parents and children are available. So need a solution that is dynamic in nature.

Also, the real problem is looping through till the leaf nodes in the directory structure.

1 Like

Hi @Dhana_M ,

Thanks. I saw that after I sent the answer. I’m working on a second solutino that should help.

Best,

Robert

1 Like

@Dhana_M,

Here’s the best way I can find do do it. You can use self joins to find parents, grandparents, and how ever many more levels you want. Then output folder id’s that have a parent, grandparent, or more that match the folder you want to export from.