I want to get a file names after _ symbol .
EX: File name = ABC45689_123456
Output should be = 123456
I am using below expression to get all the file names without extension .
Var1 =new System.IO.DirectoryInfo("FolderPath").GetFiles().Select(Function(file) Path.GetFileNameWithoutExtension(File.Name)).ToArray()
I want the expected output without using For Each activity. I am able to get it with For each
activity. (System.Text.RegularExpressions.Regex.Match(file.ToString,”(?<=_).*(\d)”).ToString.Trim)
(From x in new System.IO.DirectoryInfo("FolderPath").GetFiles()
Let fn = Path.GetFileNameWithoutExtension(x.Name)
Let m = System.Text.RegularExpressions.Regex.Match(fn,strPatternVar)
Select v = m.Value.Trim).ToArray()
we would recommend additional to enhance:
handling case not matching the pattern
recheck and adapt the regex pattern
strPatternVar = “YourRegexPatttern”
Yes, that’s what I want to do but I am confused on variable types. File list I am getting in Array of String variable. Now How should I get those and split ?
Assign Activity
arrFileParts | String() a String Array =
(From x in new System.IO.DirectoryInfo("FolderPath").GetFiles()
Let fn = Path.GetFileNameWithoutExtension(x.Name)
Let m = System.Text.RegularExpressions.Regex.Match(fn,strPatternVar)
Select v = m.Value.Trim).ToArray()
Var1 = new System.IO.DirectoryInfo("FolderPath").GetFiles().Select(Function(file) Path.GetFileNameWithoutExtension(File.Name).Split("_"c).Last).ToArray()
Hey @Nithinkrishna Thank you so much. How should I know that the names are correct ? I mean I want to get those names and will compare those to my database data.
I just want that values in my log that the file name is 123.
I am using if condition to compare with my database data.
Above statement is giving me files in Array list. I am checking particular file name from DB to this list if available. and that code I am using in IF , which is working fine.
I just want to get single file name from this array list , file A, file B, file C… without using for each activity.
Otherwise you can just reference the array indexes ie myArray(0), myArray(1), etc but then you have to know how many items there are in the array and manage a counter etc. For Each does this all for you. It’s why it exists.