Validate item name starts with


hi guys i want to use “foreach” for each item in a directory with extension .xls and file name starts with “Network Attack”. the condition for .xls is working fine but the condition for file name starts with network attack is not working.
i tried :
item.ToString.StartsWith(“Network Attack Report”)
item.ToString.StartsWith(“Network Attack Report”)=true
Path.GetFileName(item.ToString) = “Network Attack *”
but they dont work

anyone knows the solution ?

Hi @RobertoEwaldo

Can you try with item.tostring.contains(“Network”)

it works, but why cant i use starts with ? :thinking:


Try this one:


nope, still doesn’t work bro

Hi @RobertoEwaldo,

Contains will search for “Network” in the whole string.
But starts with will search for exact “Network” in the start of the string.
Its better to use contains, but if you want to use starts with can you print what value has item.tostring


As @anil5 mentioned, first try to print the value of item.toString and check whether string is started with “network” or not. If it is not started with that word then we can’t use StartsWith method.

it shows the item path too, is there any way i can get the file name only ?



Hi @RobertoEwaldo,

Item is representing the full path of the file, so you can’t use item

You have to use path.GetFileNameWithoutExtension(item.ToString).StartsWith(“Network”)

thanks it worked :+1:

Good to hear it worked for you.

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