<Reading files with varying names> Can we read a file from a folder just by its extension and not full name? Need help for this

I have a folder XYZ which has 3 files with extension .jpg, .txt , .pdf and their names are not constant. How can I read this file with activity read text file with just the extension name and not complete file name.

so long as there was only one txt file in the folder

you can do a for each file in folder activity with .txt filter enabled

1 Like

Hi @anjasing

→ Use For each file in folder activity and there is a option called Filter by in that field give the extension which files you want to get. (*.txt). Output - CurrentFile
→ Inside for each insert the Read text file activity and give the CurrentFile to the File name field of the Read text file activity.

Check the below image for better understanding,

Hope it helps!!

1 Like

hey @anjasing
To get the list of files matching to your extension you can:

  • Create a variable
    txtFiles (String) = Directory.GetFiles("YourDirectory", "*.txt")

Now, you can use for each activity to read each file.

1 Like

Hi Can I pass here different extensions like .jpg/.jpeg/.png in filter by??
@mkankatala

1 Like

You cannot pass multiple extensions in filter you are able to pass only one… @anjasing

Hope you understand!!

1 Like

Thank you so much. Got it. It worked. :slight_smile:

You can write an expression that uses multiple filters.

For @mkankatala too

Hi @postwick

We can filter out multiple extensions with expression as mentioned in your post.

But Is it possible to pass multiple extension in the filter option in For each file in folder activity…?

No, so just write an expression that gets a list of all the files you want and use that expression in a regular For Each. The result is identical to For Each File in Folder.

1 Like

Yes @postwick but in the beginning of the Post, they want to filter only .txt extension files, that’s why I suggested to use For each file in folder activity which is easy to use.

If they asked about multiple extension filtration then I’ll surely suggest them to use the expression for it.

And Thank you for the thread which is very useful for the Directory filtration expressions.

1 Like

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