Getting File Names from Directory

This question is about how to get the actual filename out of the variable:

I am currently looking to upload files that start with the same thing regardless of how they end to a private email server. The access to the server works great, the upload works great if I have the exact file name, but then I might as well just do it myself.
Here’s what I need, I need to get the list of files in a location then pattern match the name and if the pattern matches then store the name into a variable for later use. Because of how the private email server is setup I can only attach one file at a time. I need to be able to type the file name into a filename bar.
The issue I’m running into is I’m not sure how to use the directory.GetFiles(“filepath”) to obtain a string or array of strings. I tried using a for each and it can’t convert from object to string, I tried simply assigning a variable with variable type System.String but when that is pushed out to a message box it just outputs “System.String” instead of the data I want. Upon further research I tried changing the typeargument in the for each activity to string using directory.GetFiles(“filepath”) in my in statement and then using an assign activity to add it to a variable then afterwards used a message box to show what was there…the message box was blank.
Unfortunately I cannot attach screenshots or the xaml file. I did my best to explain what I’ve tried and what I need.


Try something like this:


Hi @mhall,

In for each row give directory.getfiles(“Provide Path”)
In for each keep message box & check it
In message box write item

Question about the screenshot you sent, how do I output the write line? Can I store it as a variable? This is the first time I’ve used that particular activity.

Thanks @varunk for responding, that appears to have worked, now how do I get each item into a variable that I can use the ‘Is Match’ activity on? When I was experimenting with the assign activity it didn’t seem to work.

Yes you can store it in a string variable.

Just using the Assign activity? and as a string not an array of strings?


The directory.getfiles returns an array of string.
If you loop an array of string, each loop will give you a string using the Path.GetFilename(file).tostring.

You can incorporate your logic inside the loop whic iterates every file.

that makes sense. Thank you!

Explained in this tutorial along with invoces prosessing from list of invoices in folder