Get PDF file details only from a Folder and subfolder inside the same Folder

I need to get file details of PDF files saved in a directory and its sub folders.
Eg: C:\Primary —> Inside this directory I need to get all PDF files eventhough it is found inside the subfolder
1.) C:\Primary\test1.pdf
2.) C:\Primary\SubFolder1\test2.pdf

I tried using Directory.GetFiles(“C:\Primary”,"*.pdf"), this is not picking files from the sub folder.

Please suggest some idea

@Deeipauk try getting all subfolders in the directory first using Directory.GetDirectories(“Folder Path”).
check this post.

Once you have all subfolders in an array.
Use a for each item in subfolders array and use Directory.GetFiles(“C:\Primary"+item,"*.pdf")

Always good to search for similar topics too. Here’s a similar one: How to find files in folders?


Thanks for your response. The topic you shared gave me the idea
Directory.GetFiles(“C:\Primary”,"*.pdf",SearchOption.AllDirectories) – This works

Also I was exploring yesterday and found an activity - Get Files , search type = All Directories
Package - UiPath.DirectorySearch.Activity

fileList var should of type - List of String

Thanks for your reply but this will be bit time consuming.

this should be fine. Just for your information :slight_smile: