How to read excel files from specific folders?

Hi guys!

I need to read each excel in this directory: C:\DBK\Testes RPA Envio

So I tried this:

Assign: string > directory.GetFiles(“C:\DBK\Testes RPA Envio”,"*.xlsm",SearchOption.AllDirectories)

It worked, however in each directory, I have 2 sobfolders, “WP_DAA_PENDING” and “WP_DAA_PROCESSED”

But, I need only read the excel file from the folder “WP_DAA_PENDING”

Anyone could help me with this?

Thanks for your attention

You can get the list of all folders first. Then within each folder/WP_DAA_PENDING you can do what you are trying to do.

String[] folders = Directory.GetDirectories(“C:\DBK\Testes RPA Envio")

For each folderName in folders
string > directory.GetFiles(folderName + "/WP_DAA_PENDING","*.xlsm")

This is something that I can think of.

2 Likes

I’ve got what you said.

But The folders name will change, because I’ve hundreds, thousands, of names, so I’ll have thousands of folders name diferent like this: C:\DBK\Testes RPA Envio\Akinori Yamano

I’ll always have this structure of path: C:\DBK\Testes RPA Envio\ + name + \WP_DAA_PENDING

But thanks for helping :slight_smile:

1 Like

yes I got this

But folderName in the below format covers till C:\DBK\Testes RPA Envio\ + name + \

For each folderName in folders
string > directory.GetFiles(folderName + "/WP_DAA_PENDING","*.xlsm")

so this will run for each of those 1000 folder names :slight_smile:

2 Likes