Get Filename with variable part

Hello guys,

how can I get an exact filename with an variable part?

I have a folder with different file versions inside. For example:

  1. Summary_30.04.2019.xlsx
  2. Summary_30.04.2019_v2.xlsx
  3. Summary_30.04.2019_v3.xlsx

Now I want to copy only the file 1) but keeping the part 30.04.2019 variable because next time i have to copy only the file summary_31.05.2019.xlsx.

I take the for each activity (item) to read the folder and then an if-condition with following condition:


But it seems the wildcard does not work for that function.

How can I get only file 1) and next time again but with another date string inside the filename?

Many thanks for your help!

1 Like

Buddy you can get the file name of xlsx like @Akimbow


This gives us the collection of files from the folder we mentioned

1 Like

If all the files belong to 2019, then you can use simply the following condition -

path.getfilename(item).contains(“Summary_”) AND path.getfilename(item).contains(“2019.xlsx”)

Unfortunately not. The year have to be variable as well otherwise I have to change the code every year.
Do you have another idea?

you can store the year in a variable and use it in the code -

strYear = DateTime.Now.ToString("yyyy")

path.getfilename(item).contains(“Summary_”) AND path.getfilename(item).contains(" + strYear + ".xlsx”)

But with your wildcard * it will copy the other files as well and I only want to have the first file 1).

1 Like

Buddy @Akimbow

Here is your xaml budy

Just used a condition like this it worked
path.GetFileName(item).Contains(“Summary_”) and not path.GetFileName(item).Contains("_V")
Hope Its resolved
Read (28.5 KB)

This would give all the files without mentioned versions and from that you can select the file yu want buddy


Hi @Akimbow,

Will there be a chance that you run separate files together, or is it something like on 10.05.2019 you execute your process and pick only the files with “today’s” date?

Because if so, you can try the function instead of the * in Palaniyappan’s statement.

Let us know what works for you and what doesn’t!


Thanks for your help @KarthikByggari, @Palaniyappan and @abdullahnj.

The solution of @KarthikByggari works fine but I have another problem.

The file will always be copied from the folder of the previous month. So if we have the 31.01.2020 and the file is tried to copy from the pre month Folder of 31.12.2019 the filter with the won’t work.
If you have an solution for that as well that would be great otherwise I will work with the function until end of the year and think about myself.

Thank you all.

One more condition will do that -

strPrvYear = DateTime.Now.AddDays(-1).ToString("yyyy")

In the condition part -

(path.getfilename(item).contains(" + strYear + ".xlsx”) OR path.getfilename(item).contains(" + strPrvYear + ".xlsx”))


Perfect. Thank you very much :slight_smile:

1 Like

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