How can we check a specific language month names in an excel filename?

Hi All,

I will be getting excel files every month in which spanish language month names will be added.
For e.g. Employee Details junio 2021.xlsx and I need to process these excel files in next month
June month file will get processed in July month.
How can I check for spanish month names from a file name in a folder?

Please Help.

Hi @Poonam_Yadav,

  1. Get all the files from a folder using Directory.GetFiles(FolderPath)
  2. Use for each activity to get the file name Path.GetFileName(FilePath)
  3. Use Regular expression to get the month name from the filename string
  4. You can use a mapping file or you can use the language translator to convert the spanish to english

Regards,

1 Like

Hi @Poonam_Yadav

Refer to the xaml below!

Main.xaml (7.4 KB)

Regards

Hi @Poonam_Yadav ,

We can Convert the Current Language Month Name to a Spanish Name using the Culture Info.

As you would need to get the Previous Month Name in Spanish, The Culture Info Code would be es-ES.

We can get the Converted Month Name as below :

Now.AddMonths(-1).ToString("MMMM",System.Globalization.CultureInfo.GetCultureInfo("es-ES"))

We can use this Code in the Directory.GetFiles method of accessing the files as below :

Directory.GetFiles("YourFilePath","*"+Now.AddMonths(-1).ToString("MMMM",System.Globalization.CultureInfo.GetCultureInfo("es-ES"))+"*")

Here is a List of Culture Info or Country Codes for the Culture Info :

3 Likes

Hey @Poonam_Yadav! Lets go to the solution!

  • Step 1: We are going to define a variable of type CultureInfo “culture” that will contain our Spanish culture information.

  • Step 2: Let’s now define the date of Today and store it in a variable of type Datetime “date_today”, this is because we are going to extract from this variable the desired month (current month -1)

  • Step 3: Let’s define a String array that will contain the files of interest that we are going to return.

  • Step 4: And finally we will have a variable of type String “str_lastMonthSpanish” that will store month-1 in Spanish in full.

Now let’s get to the code!

  • Step 5: First let’s extract the name of the month in Spanish.
date_today.AddMonths(-1).ToString("MMMM", culture).ToLower

  • Step 6: Next we will extract the files that have month-1 in Spanish in their name.
System.IO.Directory.GetFiles("C:\Users\gabriel.ribas\Desktop","*.xlsx").Where(Function(f) System.IO.Path.GetFileNameWithoutExtension(f).ToLower.Contains(str_lastMonthSpanish)).ToArray

Hope it helps!!

The .xaml
Main.xaml (8.9 KB)

3 Likes