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 ,
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 :
2 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
- Step 7: Checking the results.
Hope it helps!!
The .xaml
Main.xaml (8.9 KB)
2 Likes