How to retrieve both pdf and doc file from a directory?

Hi Guys,

I have a folder in which there are three kinds of files- docx, pdf, and text.
But I want to retrieve only pdf and docx and not a text file.
Using the below I wasn able to retrieve pdf files
Directory.GetFiles(in_TransactionItem, “*.pdf” )
but using this->Directory.GetFiles(in_TransactionItem, “.pdf" ,".docx”), it is throwing an error as shown below:

I know the syntax for getting two files types is incorrect.
Could you please suggest a better approach?


You can only search for one extension at a time. So Directory.GetFiles(in_TransactionItem, “.pdf") is valid for getting an array of string paths to pdf files. You can write separate variables to house the different filetypes you’re retrieving.

1 Like

Hi @Ashish_Verma,

Try this

Create a List<String> variable and assign all the file extensions
Then create String[] variable assign the below code and try it foreach activity

1 Like

This works. Thank you :slight_smile:

Thank you. I tried this step and the one mentioned below and both works. :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.