How to take only year or 4 digits (year) from file name

Hi I have a filename Peter Johny_Report_25042020.pdf
how can i take variable only for 2020
my point is i want to assign variable for each file based on year and then move files to folder (2020, for 2019 to folder 2019)
thank you

Hi @Marian_Lai_SK

Welcome to forums

Check as below

Right(samplestring.Split("."c)(0).ToString, 4)

Hope this helps you

Thanks

thank you ksrinu but it does not work :confused:

@Marian_Lai_SK

I see there was extra symbol after closing bracket, remove and try again

Right(item.Split("."c)(0).ToString, 4)

Hope this helps you

Thanks

1 Like

You can use this single regex code, @Marian_Lai_SK
System.Text.RegularExpressions.Regex.Match(“Peter Johny_Report_25042020.pdf”,"(\d{4})\s?\.").Groups(1).ToString.Trim
Hope this may help you :slight_smile:

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