Find a file with extension

Can you tell me how to find a file in a folder with a specific extension? For example, png.

1 Like

There may be several possible solutions. Suppose that the array with names is called files_array.

1. filtered_array = files_array.filter(x => x.includes(".jpg")) - filter the array so that all the elements that have the .jpg extension remain.
2. Cycle by files_array. Use the “File Information” function and specify the full path. At the output we get the object with the values. One of the fields is extension. Further condition: if current_file_info.extension === "jpg", you execute a branch. If not, you do not execute or execute another one. Since your file array contains only names, and we need full paths, you can add the rest of the path to all the elements at once. For example: files_array.map(x => "C:\\tmp\\" + x)

1 Like

This thread and another one have been really helpful! I ended up using the following logic:

image

However, this is only part 1 of my scenario. We have folders for all 50 states, DC, PR, and VI. Some of these folders will have files with .txt, others will have .xlsx, and then CA will have .xml. It would be nice to just have one process that checks for any of those situations. However, that’s not the real issue.

What I would ultimately like to do is to have some logic that checks to see if a file exists in a directory. Since the state files can vary in their names due to a random code being generated, I elected to go with the file extension. I noticed that when I use this logic with a User Notification activity, I either get the filename or two brackets [ ]. When I use this logic with a File Found activity, it always moves to the “Yes” logic, showing “true” as the value.

What logic can I use to get the filename based on the file extension and then check to see if the file exists? I tried using If…Then logic after the 3rd activity. I used both Basic and Advanced conditions with various operators as well as using trying to convert to string before filtering; however, everything comes us Yes/Yes or No/No. It would seem that I have the best way to capture the filename if it exists; however, what would be the best way to check if the file was found? I hope that was clear. I’m including screenshots of various situations below to help. Thank you in advance!

The following screenshot shows how a directory will look when the file exists:
image

The following screenshot shows how the logic works when the file exists:
image

The following screenshot shows how a directory will look when the file doesn’t exist:
image

The following screenshot shows how the logic works when the file doesn’t exist:
image

2 Likes

In case anyone else needs something like this, I have a solution. I reached out to the very awesome @Timothy_Collins to get some assistance on this topic. He provided me with a solution that I was able to modify for my own purposes. ElectroNeek is very fortunate to have him as part of the company! He has been a strong supporter for us from day 1.

3 Likes