Find list of all the sub folders and files inside a a folder or a share point URL

Hi team

I have a use-case that requires me to get a list of all the subfolders and the files present in the master folder and that master folder can either be on share point link or on local

so how can I create a list which proper details

sample input structure:

sample output structure:

Can anyone please help me out with this use-case?

thankyou :slight_smile:

Hi @Aishwarya_Bhargava !

You can use the following function to extract all the subfiles from an original folder, independently if it is a local folder, or a synced sharepoint folder:


Expression description:

· var_FolderPath = Local path to extract files from.
· "*.*" = filter. If you'd like only PDF's for example, this would be "*.pdf*".
· SearchOption.Alldirectories = In order to look for files inside subfolders also.

This will not give you the desired structure you pasted on the 2nd screenshot, but will give you an array of strings, with the full path to each file:

Files found:

C:\Users\User\OneDrive - DemoFolder\Documents\\FolderA\FolderAA\FileA.txt
C:\Users\User\OneDrive - DemoFolder\Documents\\FolderB\FileA.txt
C:\Users\User\OneDrive - DemoFolder\Documents\\FolderB\FileA_1.xlsx
C:\Users\User\OneDrive - DemoFolder\Documents\\FolderC\FolderCC\FileCC1.txt
C:\Users\User\OneDrive - DemoFolder\Documents\\FolderC\FolderCC\FileCC2.pdf

With this list of final paths, you can manipulate the strings to get your desired DT output. But might be worth to leave it like this, if it suits your automation.

Other useful expressions you can use to extract filenames from this array of strings:

-> This would return exactly "FileA.txt" from the 1st value in our example.

Best Regards,

Hi @Aishwarya_Bhargava,

Just as how @ignasi.peiris explained, you can use Directory.GetFiles to get all the files in a folder (including subfolders with SearchOption.AllDirectories). Similar to that, you can use Directory.GetDirectories to get all the folders.

Using those two, and a for each / for each folder in folder, you can simply loop through all the subfolders and get the output exactly as in the sample.
Here is an workflow doing just that, in case you need an example: (65.2 KB)

Best Regards,

1 Like